Example usage for android.widget EditText getText

List of usage examples for android.widget EditText getText

Introduction

In this page you can find the example usage for android.widget EditText getText.

Prototype

@Override
    public Editable getText() 

Source Link

Usage

From source file:com.socialapp.eventmanager.LoginActivity.java

public void signup(View view) {

    EditText emailView = (EditText) findViewById(R.id.email);
    EditText pwView = (EditText) findViewById(R.id.password);
    final Context currContext = this;
    String email = emailView.getText().toString();
    String password = pwView.getText().toString();

    if ((emailView.getText().toString()).matches("")) {
        Toast.makeText(this, "Please enter your email id", Toast.LENGTH_SHORT).show();
    } else {// w w  w .  j  a va2s  .c  om
        Log.d(TAG, "Attempting to login with email: " + email + " password: " + password);
        Backend.signUp(email, password, new Backend.BackendCallback() {
            @Override
            public void onRequestCompleted(final String result) {

                //Log.d(TAG, "Login success. User: " + user.toString());

                runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onRequestFailed(final String message) {

                //NOTE: parameter validation and filtering is handled by the backend, just show the
                //returned error message to the user
                Log.d(TAG, "Received error from Backend: " + message);
                runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
}

From source file:cm.aptoide.pt.ManageRepo.java

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

    LayoutInflater li = LayoutInflater.from(this);

    switch (item.getItemId()) {
    case ADD_REPO:
        View view = li.inflate(R.layout.addrepo, null);

        final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
        final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

        final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
        final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

        final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
        sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sec_user.setEnabled(true);
                    sec_pwd.setEnabled(true);
                } else {
                    sec_user.setEnabled(false);
                    sec_pwd.setEnabled(false);
                }//from   ww  w.j a va 2s. com
            }
        });

        Builder p = new AlertDialog.Builder(this).setView(view);
        alrt = p.create();
        alrt.setIcon(android.R.drawable.ic_menu_add);
        alrt.setTitle("Add new repository");

        alrt.setButton("Add", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Message msg = new Message();
                EditText uri = (EditText) alrt.findViewById(R.id.edit_uri);
                String uri_str = uri.getText().toString();
                sec_msg.setVisibility(View.GONE);
                sec_msg2.setVisibility(View.GONE);
                if (sec.isChecked()) {
                    String user = sec_user.getText().toString();
                    String pwd = sec_pwd.getText().toString();
                    int result = checkServer(uri_str, user, pwd);
                    if (result == 200) {
                        msg.obj = 0;
                        db.addServer(uri_str);
                        db.addLogin(user, pwd, uri_str);
                        change = true;
                        redraw();
                    } else if (result == 401) {
                        sec_msg2.setText("Login is wrong");
                        sec_msg2.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    } else {
                        sec_msg.setText("Can't connect to server");
                        sec_msg.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    }
                } else {
                    int result = checkServer(uri_str, null, null);
                    if (result == 200) {
                        msg.obj = 0;
                        db.addServer(uri_str);
                        change = true;
                        redraw();
                    } else if (result == 401) {
                        sec_msg2.setText("Login required");
                        sec_msg2.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    } else {
                        sec_msg.setText("Can't connect to server");
                        sec_msg.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    }
                }
                new_repo.sendMessage(msg);
            }
        });

        alrt.setButton2("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                alrt.dismiss();
            }
        });
        alrt.show();
        break;

    case REM_REPO:
        final Vector<String> rem_lst = new Vector<String>();
        CharSequence[] b = new CharSequence[server_lst.size()];
        for (int i = 0; i < server_lst.size(); i++) {
            b[i] = server_lst.get(i).uri;
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Chose repository to remove");
        builder.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
        builder.setMultiChoiceItems(b, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
                if (isChecked) {
                    rem_lst.addElement(server_lst.get(whichButton).uri);
                } else {
                    rem_lst.removeElement(server_lst.get(whichButton).uri);
                }
            }
        });
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                db.removeServer(rem_lst);
                change = true;
                redraw();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
        break;

    case EDIT_REPO:
        CharSequence[] b2 = new CharSequence[server_lst.size()];
        for (int i = 0; i < server_lst.size(); i++) {
            b2[i] = server_lst.get(i).uri;
        }

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle("Chose repository to edit");
        builder2.setIcon(android.R.drawable.ic_menu_edit);
        builder2.setSingleChoiceItems(b2, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                updt_repo = server_lst.get(which).uri;
            }
        });
        builder2.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                editRepo(updt_repo);
                return;
            }
        });
        builder2.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        alert2 = builder2.create();
        alert2.show();
        break;
    }
    return super.onMenuItemSelected(featureId, item);
}

From source file:fm.smart.r1.CreateExampleActivity.java

public void onClick(View v) {
    EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence);
    EditText translationInput = (EditText) findViewById(R.id.create_example_translation);
    EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration);
    EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration);
    final String example = exampleInput.getText().toString();
    final String translation = translationInput.getText().toString();
    if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) {
        Toast t = Toast.makeText(this, "Example and translation are required fields", 150);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();/*w  w w .  j  a  v a2  s.  co  m*/
    } else {
        final String example_language_code = Utils.LANGUAGE_MAP.get(example_language);
        final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language);
        final String example_transliteration = exampleTransliterationInput.getText().toString();
        final String translation_transliteration = translationTransliterationInput.getText().toString();

        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
            // navigation
            // back to this?
            LoginActivity.return_to = CreateExampleActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("goal_id", goal_id);
            LoginActivity.params.put("item_id", item_id);
            LoginActivity.params.put("example", example);
            LoginActivity.params.put("translation", translation);
            LoginActivity.params.put("example_language", example_language);
            LoginActivity.params.put("translation_language", translation_language);
            LoginActivity.params.put("example_transliteration", example_transliteration);
            LoginActivity.params.put("translation_transliteration", translation_transliteration);
            startActivity(intent);
        } else {

            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Creating Example ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread create_example = new Thread() {
                public void run() {
                    // TODO make this interruptable .../*if
                    // (!this.isInterrupted())*/
                    try {
                        // TODO failures here could derail all ...
                        CreateExampleActivity.add_item_goal_result = new AddItemResult(
                                Main.lookup.addItemToGoal(Main.transport, goal_id, item_id, null));

                        Result result = null;
                        try {
                            result = Main.lookup.createExample(Main.transport, translation,
                                    translation_language_code, translation, null, null, null);
                            JSONObject json = new JSONObject(result.http_response);
                            String text = json.getString("text");
                            String translation_id = json.getString("id");
                            result = Main.lookup.createExample(Main.transport, example, example_language_code,
                                    example_transliteration, translation_id, item_id, goal_id);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        CreateExampleActivity.create_example_result = new CreateExampleResult(result);

                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    myOtherProgressDialog.dismiss();

                }
            };
            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    create_example.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    create_example.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            myOtherProgressDialog.show();
            create_example.start();
        }
    }
}

From source file:fr.mdk.kisspush.KISSPush.java

protected void openAdd() {
    final Activity act = this;
    // get prompts.xml view
    LayoutInflater layoutInflater = getLayoutInflater();
    View promptView = layoutInflater.inflate(R.layout.prompts, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(act);
    // set prompts.xml to be the layout file of the alertdialog
    // builder//from  w  w w . j a v  a 2  s .c  o m
    alertDialogBuilder.setView(promptView);
    final EditText input = (EditText) promptView.findViewById(R.id.userInput);
    // setup a dialog window
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // get user input and set it to
            // result
            if (input.getText().toString().length() > 0) {
                kiss_push_cli.add_alias(input.getText().toString(), new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
                        getAliases();
                    }
                });
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create an alert dialog
    AlertDialog alertD = alertDialogBuilder.create();
    alertD.show();

}

From source file:app.zeeshanz.foodisfyuser.app.ViewerSettingsDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    getDialog().setTitle(R.string.settings);
    View dialogView = inflater.inflate(R.layout.viewer_settings, container);

    final CheckBox syntheticSpread = (CheckBox) dialogView.findViewById(R.id.syntheticSpread);
    syntheticSpread.setChecked(mOriginalSettings.isSyntheticSpread());

    final EditText fontSizeText = (EditText) dialogView.findViewById(R.id.fontSize);
    fontSizeText.setText("" + mOriginalSettings.getFontSize());

    final EditText columnGapText = (EditText) dialogView.findViewById(R.id.columnGap);
    columnGapText.setText("" + mOriginalSettings.getColumnGap());

    Button ok = (Button) dialogView.findViewById(R.id.ok);
    ok.setOnClickListener(new View.OnClickListener() {

        @Override//from  w w w.  ja  va 2s. c o  m
        public void onClick(View v) {
            if (mListener != null) {
                int fontSize = parseString(fontSizeText.getText().toString(), 100);
                int columnGap = parseString(columnGapText.getText().toString(), 20);
                ViewerSettings settings = new ViewerSettings(syntheticSpread.isChecked(), fontSize, columnGap);
                mListener.onViewerSettingsChange(settings);
            }
            dismiss();
        }

        private int parseString(String s, int defaultValue) {
            try {
                return Integer.parseInt(s);
            } catch (Exception e) {
                Log.e(TAG, "" + e.getMessage(), e);
            }
            return defaultValue;
        }
    });

    Button cancel = (Button) dialogView.findViewById(R.id.cancel);
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    return dialogView;
}

From source file:com.example.lilach.alsweekathon_new.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ///////////////////////////////////////////
    try {/*from  ww w .  j a  v  a 2 s. com*/
        String yourFilePath = Environment.getExternalStorageDirectory() + "/"
                + "spiralStairs_CalInertialAndMag.csv";
        CSVReader reader = new CSVReader(new FileReader(yourFilePath));

        String[] nextLine;
        //skip the first line - headers
        reader.readNext();
        LinkedList<Signal> signals = new LinkedList<Signal>();

        for (int i = 0; i < 3; i++) {
            nextLine = reader.readNext();
            // while ((nextLine = reader.readNext()) != null) {
            // nextLine[] is an array of values from the line
            System.out.println(nextLine[0] + nextLine[1] + "etc...");
            Signal signal = new Signal();
            signal.setTimestamp(new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date()));
            signal.setPacketId(Integer.parseInt(nextLine[PACKET_NUMBER_INDEX]));
            signal.setAccelerometer(new XYZValues(Float.parseFloat(nextLine[ACCELEROMETER_X_INDEX]),
                    Float.parseFloat(nextLine[ACCELEROMETER_Y_INDEX]),
                    Float.parseFloat(nextLine[ACCELEROMETER_Z_INDEX])));
            signal.setGyro(new XYZValues(Float.parseFloat(nextLine[GYROSCOPE_X_INDEX]),
                    Float.parseFloat(nextLine[GYROSCOPE_Y_INDEX]),
                    Float.parseFloat(nextLine[GYROSCOPE_Z_INDEX])));

            signals.add(signal);

        }

        serverRequest sr = new serverRequest();
        sr.setSignals(signals);
        sr.setUserid("user");
        sr.setTimestamp("111111");

        //send the data to the server: Json, Post
        Gson gson = new Gson();
        String json = gson.toJson(sr);
        Log.d("aa", json);
        makeRequest("http://alsvm.cloudapp.net:8080/signals/user", json);
        // HttpResponse a = makeRequest("http://alsvm.cloudapp.net:8080/signals/user", json);
        // Log.d("httpResponse", a.toString());

        //            List myEntries = reader.readAll();
        //            System.out.println("size: " +myEntries.size());
        //            System.out.println("first item: "+myEntries.get(0));

    } catch (IOException e) {
        Log.d("exception: ", e.getMessage());
    }

    //////////////////////////////////////////////

    setContentView(R.layout.main);
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    /// service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    //                    if (mDevice!=null)
                    //                    {
                    //                       //mService.disconnect();
                    //
                    //                    }
                }
            }
        }
    });
    // Handler Send button
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                //mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:com.download.android.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);//  ww w  . j  a va  2s  . c  om

    final EditText edtTxt = (EditText) findViewById(R.id.editText1);
    Button btnSend = (Button) findViewById(R.id.buttonSend);
    Button btnDownload = (Button) findViewById(R.id.btnDownload);
    Button btnUpload = (Button) findViewById(R.id.btnUpload);
    Button btnCookie = (Button) findViewById(R.id.btnCookie);

    edtResp = (EditText) findViewById(R.id.edtResp);

    btnSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String name = edtTxt.getText().toString();
            //item.setActionView(R.layout.progress);
            SendHttpRequestTask t = new SendHttpRequestTask();

            String[] params = new String[] { url, name };
            t.execute(params);
        }
    });

    btnDownload.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, DownloadActivity.class);
            startActivity(i);
        }
    });

    btnCookie.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, CookieActivity.class);
            startActivity(i);
        }
    });

    btnUpload.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, UploadActivity.class);
            startActivity(i);
        }
    });

}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedActionsFragment.java

public void broadcastGps() {
    final CharSequence[] items = { "5 minutes", "15 minutes", "1 hour", " 24 hours" };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Choose duration of broadcast");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, final int item) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setMessage("Enter a secret key if you want to:");
            final EditText input = new EditText(getActivity());
            alert.setView(input);/*from  w  ww  .  j av a 2 s .  c o  m*/
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    final String password = input.getText().toString();
                    myLocation = new MyLocation();
                    locationResult = new MyLocation.LocationResult() {
                        final ProgressDialog dialog = ProgressDialog.show(getActivity(), "",
                                "Preparing broadcast...", true);

                        @Override
                        public void gotLocation(final Location location) {
                            //Got the location!
                            try {
                                int minutes;
                                if (item == 0) {
                                    minutes = 5;
                                } else if (item == 1) {
                                    minutes = 15;
                                } else if (item == 2) {
                                    minutes = 60;
                                } else if (item == 3) {
                                    minutes = 1440;
                                } else {
                                    minutes = 5;
                                }

                                Uri uri = new Uri.Builder().scheme("http").authority("suif.stanford.edu")
                                        .path("dungbeetle/nearby.php").build();

                                StringBuffer sb = new StringBuffer();
                                DefaultHttpClient client = new DefaultHttpClient();
                                HttpPost httpPost = new HttpPost(uri.toString());

                                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                                nameValuePairs.add(new BasicNameValuePair("group_name", mGroupName));
                                nameValuePairs
                                        .add(new BasicNameValuePair("feed_uri", mExternalFeedUri.toString()));
                                nameValuePairs.add(new BasicNameValuePair("length", Integer.toString(minutes)));
                                nameValuePairs.add(
                                        new BasicNameValuePair("lat", Double.toString(location.getLatitude())));
                                nameValuePairs.add(new BasicNameValuePair("lng",
                                        Double.toString(location.getLongitude())));
                                nameValuePairs.add(new BasicNameValuePair("password", password));
                                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                try {
                                    HttpResponse execute = client.execute(httpPost);
                                    InputStream content = execute.getEntity().getContent();
                                    BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
                                    String s = "";
                                    while ((s = buffer.readLine()) != null) {
                                        sb.append(s);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                String response = sb.toString();
                                if (response.equals("1")) {
                                    Toast.makeText(getActivity(), "Now broadcasting for " + items[item],
                                            Toast.LENGTH_SHORT).show();
                                } else
                                    Log.w(TAG, "Wtf");

                                Log.w(TAG, "response: " + response);
                            } catch (Exception e) {
                            }

                            dialog.dismiss();
                        }
                    };
                    locationClick();
                }
            });
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            });
            alert.show();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:markson.visuals.sitapp.settingActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);//from  w  w w .  j  a  v  a2s . c  o  m

    new notifyAsync().execute();

    try {
        Class<?> strictModeClass = Class.forName("android.os.StrictMode", true,
                Thread.currentThread().getContextClassLoader());

        Class<?> threadPolicyClass = Class.forName("android.os.StrictMode$ThreadPolicy", true,
                Thread.currentThread().getContextClassLoader());

        Class<?> threadPolicyBuilderClass = Class.forName("android.os.StrictMode$ThreadPolicy$Builder", true,
                Thread.currentThread().getContextClassLoader());

        Method setThreadPolicyMethod = strictModeClass.getMethod("setThreadPolicy", threadPolicyClass);

        Method detectAllMethod = threadPolicyBuilderClass.getMethod("detectAll");
        Method penaltyMethod = threadPolicyBuilderClass.getMethod("penaltyLog");
        Method buildMethod = threadPolicyBuilderClass.getMethod("build");

        Constructor<?> threadPolicyBuilderConstructor = threadPolicyBuilderClass.getConstructor();
        Object threadPolicyBuilderObject = threadPolicyBuilderConstructor.newInstance();

        Object obj = detectAllMethod.invoke(threadPolicyBuilderObject);

        obj = penaltyMethod.invoke(obj);
        Object threadPolicyObject = buildMethod.invoke(obj);
        setThreadPolicyMethod.invoke(strictModeClass, threadPolicyObject);

    } catch (Exception ex) {
        Log.w("n", "Strict not enabled....");
    }

    File file = this.getFileStreamPath("settings.dat");

    if (file.exists()) {
        loadpop();
    }

    final EditText mEdit = (EditText) findViewById(R.id.editText1);

    View.OnClickListener handler = new View.OnClickListener() {

        public void onClick(View v) {

            switch (v.getId()) {

            case R.id.crnbut:

                if (mEdit.getText().length() > 3) {
                    addnum(mEdit.getText().toString());
                    mEdit.setText("");
                    startws();
                }
                break;

            }

        }

    };

    findViewById(R.id.crnbut).setOnClickListener(handler);
}

From source file:com.citrus.sdk.fragments.SavedOptions.java

private void processCardFlow(final String txnId, final String signature, final String token) {
    final Dialog cvvDialog = new Dialog(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    cvvDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    View view = inflater.inflate(R.layout.cvv, null);
    final EditText cvvEditText = (EditText) view.findViewById(R.id.cvvText);
    final TextView errorText = (TextView) view.findViewById(R.id.errorText);
    Button payButton = (Button) view.findViewById(R.id.payButton);
    payButton.setOnClickListener(new OnClickListener() {

        @Override//from w  ww  .  j av  a  2 s  .c  om
        public void onClick(View v) {
            if (TextUtils.isEmpty(cvvEditText.getText().toString())
                    || cvvEditText.getText().toString().length() < 3) {
                errorText.setText("Invalid cvv");
            } else {
                fillDetails(txnId, signature, token, cvvEditText.getText().toString());
                cvvDialog.dismiss();
            }
        }
    });
    cvvDialog.setContentView(view);
    cvvDialog.show();
}