Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

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

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:com.eugene.fithealthmaingit.UI.SaveSearchAddItemActivityMain.java

private void updateItems() {

    mServingSizeUpdated.setText("1");

    LinearLayout changeServing = (LinearLayout) findViewById(R.id.changeServing);
    changeServing.setOnClickListener(new View.OnClickListener() {
        @Override/*from w w  w  .  ja  v  a 2 s. c om*/
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(SaveSearchAddItemActivityMain.this);

            alert.setTitle("Update Serving Size: ");
            alert.setMessage("Servings Consumed");

            final EditText input = new EditText(SaveSearchAddItemActivityMain.this);
            input.setText(mServingg.getText().toString());
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            input.selectAll();
            input.setGravity(Gravity.CENTER_HORIZONTAL);
            alert.setView(input, 64, 0, 64, 0);
            alert.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    double values = Double.valueOf(input.getText().toString());
                    mServingg.setText(df.format(values));
                    mServingSizeUpdated.setText(df.format(values));
                    mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values));
                    mCalorieProgress = Double.valueOf(mCalories) * values;
                    mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values));
                    mFatProgress = Double.valueOf(mFat) * values;
                    mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values));
                    mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values));
                    mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values));
                    mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values));
                    mCarbProgress = Double.valueOf(mCarbohydrates) * values;
                    mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values));
                    mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values));
                    mProUpdate.setText(df.format(Double.valueOf(mProtein) * values));
                    mProteinProgress = Double.valueOf(mProtein) * values;
                    mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values));
                    mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values));
                    mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values));
                    mIronUpdate.setText(df.format(Double.valueOf(mIron) * values));
                    progressBars();
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });
            alert.setCancelable(false);
            alert.show();
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });

}

From source file:com.sigilance.CardEdit.MainActivity.java

private void promptForVerifyPin(final int mode) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.action_enable_edit_mode);
    builder.setMessage(/*w w  w  . j a  va2s .  c  o  m*/
            "Enter the Admin PIN to edit data on the card.\nREMINDER: The default Admin PIN is 12345678");
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
    builder.setView(input);

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (input.getText().toString().length() == 0) {
                Toast.makeText(MainActivity.this, "Enter a PIN!", Toast.LENGTH_SHORT).show();
                return;
            }
            int minPinLength = (mode == 0x83) ? 8 : 6;
            if (input.getText().toString().length() < minPinLength) {
                input.setText("");
                Toast.makeText(MainActivity.this, String.format("PIN is at least %d digits.", minPinLength),
                        Toast.LENGTH_SHORT).show();
                return;
            }
            mPendingOperations.add(new PendingVerifyPinOperation(mode, input.getText().toString()));
            hideUi();
            findTextViewById(R.id.id_action_reqiured_warning).setText(R.string.warning_tap_card_to_verify);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.create().show();
}

From source file:me.kaidul.uhunt.MainActivity.java

void ProblemNoPicker(final int requestCode) {
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    new AlertDialog.Builder(this).setTitle("Enter problem Id").setView(input)
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();//from w  w w .  j a  v a  2 s. c  om
                }
            }).setPositiveButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String str = input.getEditableText().toString();
                    if (str.equals("")) {
                        new AlertDialog.Builder(MainActivity.this).setTitle("Invalid Problem No")
                                .setMessage("Please Enter a valid problem no.!")
                                .setNeutralButton("OK", new DialogInterface.OnClickListener() {

                                    public void onClick(DialogInterface dlg, int sumthin) {
                                        ProblemNoPicker(requestCode);
                                    }
                                }).show();
                        return;
                    }
                    problemNo = Integer.parseInt(str);
                    if (requestCode == 1) {
                        ProblemWebView searchProblem = (ProblemWebView) getSupportFragmentManager()
                                .findFragmentById(R.id.content_frame);
                        if (searchProblem != null) {
                            searchProblem.updateUrl(problemNo);
                        }
                    } else if (requestCode == 2) {
                        ProblemStatistics problemStatistics = (ProblemStatistics) getSupportFragmentManager()
                                .findFragmentById(R.id.content_frame);
                        if (problemStatistics != null) {
                            problemStatistics.updateUrl(problemNo);
                        }
                    }
                }
            }).show();
}

From source file:com.auth0.sample.ProfileActivity.java

public AlertDialog setEndpointURL(Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final EditText input = new EditText(ProfileActivity.this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(50, 50, 50, 50);//from   www. j  a v  a  2s  .  c om
    input.setLayoutParams(lp);

    builder.setView(input).setTitle("Set Endpoint URL").setPositiveButton("Set",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (input.getText().toString() != "") {
                        editor.putString("ENDPOINT_URL", input.getText().toString());
                        editor.commit();
                        refresh_handler.postDelayed(refresh_runnable, 50000);
                    } else {
                        Toast.makeText(ProfileActivity.this, "Enter An Url", Toast.LENGTH_SHORT).show();
                    }
                }
            });

    return builder.show();
}

From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java

private void doSearch() {
    final AlertDialog.Builder alertSearch = new AlertDialog.Builder(this);
    alertSearch.setTitle(getResources().getString(R.string.alertSearchTitle));
    alertSearch.setMessage(getResources().getString(R.string.alertSearchSummary));
    final EditText inputSearch = new EditText(this);
    inputSearch.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_URI);
    alertSearch.setView(inputSearch);/*from  ww w .  j  av a 2  s  . c o m*/
    alertSearch.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = inputSearch.getText().toString().trim();
            webView.loadUrl("https://encrypted.google.com/search?q=" + value);
        }
    });

    alertSearch.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });
    alertSearch.show();
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

private void processTypeLaunch(final String intentAction, final String intentUri, final String intentType,
        final String intentExtras, final String cfmMsg, String failMsgTemp, final int notifyId) {

    //if you wish, use a default generic fail message whenever undefined. recommended to use this when testing
    if (failMsgTemp.equalsIgnoreCase(""))
        failMsgTemp = "Opening URL failed!";
    final String failMsg = failMsgTemp;

    Pattern pattern = Pattern.compile("\\[ASK:(.*?)\\]");
    final Matcher matcher = pattern.matcher(intentUri);
    int count = 0;
    String askMsg = "";
    while (matcher.find()) {
        count++;/*from ww w.j  a va2s .c o  m*/
        askMsg = matcher.group(1);
    }
    if (count == 1) {
        //confirm alert with text input
        if (BleepActivity.isBackground)
            localNotification("", cfmMsg, notifyId);
        final EditText input = new EditText(BleepActivity.currentBleepActivity);
        DialogInterface.OnClickListener posFunc = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String userInput = input.getText().toString();
                String intentUri2 = matcher.replaceFirst(userInput);
                Intent launchIntent = createIntent(intentAction, intentUri2, intentType, intentExtras);
                startIntent(launchIntent, failMsg, true, cfmMsg, notifyId);
            }
        };
        DialogInterface.OnClickListener negFunc = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                // Do nothing.
            }
        };
        showAlertDialog(cfmMsg, askMsg, "OK", posFunc, "Cancel", negFunc, input);
    } else if (!cfmMsg.equalsIgnoreCase("")) {
        //confirm alert, message only, no text input
        final Intent launchIntent = createIntent(intentAction, intentUri, intentType, intentExtras);
        if (!BleepActivity.isTesting && !testIntent(launchIntent)) {
            return;
        }
        if (BleepActivity.isBackground) {
            localNotification("", cfmMsg, launchIntent, failMsg, notifyId);
        } else {
            DialogInterface.OnClickListener posFunc = new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    startIntent(launchIntent, failMsg, true, cfmMsg, notifyId);
                }
            };
            DialogInterface.OnClickListener negFunc = new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                }
            };
            showAlertDialog("", cfmMsg, "OK", posFunc, "Cancel", negFunc, null);
        }
    } else {
        //no confirm alert
        Intent launchIntent = createIntent(intentAction, intentUri, intentType, intentExtras);
        if (!BleepActivity.isTesting && !testIntent(launchIntent)) {
            return;
        }
        String tmpCfmMsg = "You have been sent a URL to view. Open?";
        if (BleepActivity.isBackground) {
            localNotification("", tmpCfmMsg, launchIntent, failMsg, notifyId);
        } else {
            startIntent(launchIntent, failMsg, true, tmpCfmMsg, notifyId);
        }
    }
}

From source file:com.gimranov.zandy.app.ItemActivity.java

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_NEW:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getResources().getString(R.string.item_type))
                // XXX i18n
                .setItems(Item.ITEM_TYPES_EN, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int pos) {
                        Item item = new Item(getBaseContext(), Item.ITEM_TYPES[pos]);
                        item.dirty = APIRequest.API_DIRTY;
                        item.save(db);//from  w w w . j  a v  a 2 s.c om
                        if (collectionKey != null) {
                            ItemCollection coll = ItemCollection.load(collectionKey, db);
                            if (coll != null) {
                                coll.loadChildren(db);
                                coll.add(item);
                                coll.saveChildren(db);
                            }
                        }
                        Log.d(TAG, "Loading item data with key: " + item.getKey());
                        // We create and issue a specified intent with the necessary data
                        Intent i = new Intent(getBaseContext(), ItemDataActivity.class);
                        i.putExtra("com.gimranov.zandy.app.itemKey", item.getKey());
                        startActivity(i);
                    }
                });
        AlertDialog dialog = builder.create();
        return dialog;
    case DIALOG_SORT:

        // We generate the sort name list for our current locale
        String[] sorts = new String[SORT_NAMES.length];
        for (int j = 0; j < SORT_NAMES.length; j++) {
            sorts[j] = getResources().getString(SORT_NAMES[j]);
        }

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle(getResources().getString(R.string.set_sort_order)).setItems(sorts,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int pos) {
                        Cursor cursor;
                        setSortBy(SORTS[pos]);
                        ItemCollection collection;
                        if (collectionKey != null
                                && (collection = ItemCollection.load(collectionKey, db)) != null) {
                            cursor = getCursor(collection);
                        } else {
                            if (query != null) {
                                cursor = getCursor(query);
                            } else {
                                cursor = getCursor();
                            }
                        }
                        ItemAdapter adapter = (ItemAdapter) getListAdapter();
                        adapter.changeCursor(cursor);
                        Log.d(TAG, "Re-sorting by: " + SORTS[pos]);

                        Persistence.write(SORT_CHOICE, SORTS[pos]);
                    }
                });
        AlertDialog dialog2 = builder2.create();
        return dialog2;
    case DIALOG_PROGRESS:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setMessage(getResources().getString(R.string.identifier_looking_up));
        return mProgressDialog;
    case DIALOG_IDENTIFIER:
        final EditText input = new EditText(this);
        input.setHint(getResources().getString(R.string.identifier_hint));

        final ItemActivity current = this;

        dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.identifier_message))
                .setView(input).setPositiveButton(getResources().getString(R.string.menu_search),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Editable value = input.getText();
                                // run search
                                Bundle c = new Bundle();
                                c.putString("mode", "isbn");
                                c.putString("identifier", value.toString());
                                removeDialog(DIALOG_PROGRESS);
                                ItemActivity.this.b = c;
                                showDialog(DIALOG_PROGRESS);
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.scan),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // If we're about to download from Google play, cancel that dialog
                                // and prompt from Amazon if we're on an Amazon device
                                IntentIntegrator integrator = new IntentIntegrator(current);
                                @Nullable
                                AlertDialog producedDialog = integrator.initiateScan();
                                if (producedDialog != null && "amazon".equals(BuildConfig.FLAVOR)) {
                                    producedDialog.dismiss();
                                    AmazonZxingGlue.showDownloadDialog(current);
                                }
                            }
                        })
                .setNegativeButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    default:
        return null;
    }
}

From source file:com.moro.synapsemod.MainActivity.java

protected void guardar_perfil() {

    AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
    adb.setTitle(R.string.dlg_backup_title);
    adb.setIcon(R.drawable.ic_action_save);
    adb.setMessage(R.string.dlg_backup_message);

    final EditText editText = new EditText(MainActivity.this);
    editText.setHint(R.string.dlg_backup_box);
    adb.setView(editText);//  w ww  . j  a  v a  2  s  .com

    // Si pulsamos OK, cargamos el dialogo de confirmacion de carga de perfil
    adb.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // Guardamos el perfil
            String name = editText.getText().toString().replace(' ', '_');
            Utils.runCommand(BB + " mount -o remount,rw /", false);
            Utils.runCommand("/res/synapse/actions/sqlite ExportConfigSynapse " + name, false);
            Utils.runCommand(BB + " mount -o remount,ro /", false);

            Toast toast = Toast.makeText(getApplicationContext(),
                    getString(R.string.dlg_bk_profile_toast) + " " + name, Toast.LENGTH_LONG);
            toast.show();
        }
    });
    // Si pulsamos Cancelar salimos
    adb.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    // create an alert dialog
    AlertDialog alert = adb.create();
    alert.show();
}