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:org.yaoha.YaohaActivity.java

private void openFavMenu(final ImageButton btn, final TextView tv) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    final EditText input = new EditText(this);
    alert.setTitle("Adding favorite");
    alert.setMessage("Enter your favorite search");
    alert.setView(input);/*from   w ww  .j  a va 2s.  co  m*/

    alert.setPositiveButton("Set", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            final Editor edit = prefs.edit();
            String tmp = "";
            tv.setText(input.getText());
            btn.setImageResource(R.drawable.placeholder_logo);
            if (btn.getId() == button_favorite_1.getId()) {
                tmp = "saved_fav_1_text";
            } else if (btn.getId() == button_favorite_2.getId()) {
                tmp = "saved_fav_2_text";
            } else if (btn.getId() == button_favorite_3.getId()) {
                tmp = "saved_fav_3_text";
            } else if (btn.getId() == button_favorite_4.getId()) {
                tmp = "saved_fav_4_text";
            } else if (btn.getId() == button_favorite_5.getId()) {
                tmp = "saved_fav_5_text";
            } else if (btn.getId() == button_favorite_6.getId()) {
                tmp = "saved_fav_6_text";
            }
            edit.putString(tmp, input.getText().toString());
            edit.commit();
            //TODO add method to catch pre-defined store-icons
        }
    });

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

From source file:ir.actfun.toofan.activities.MainActivity.java

private void searchCities() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(this.getString(R.string.search_title));
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setMaxLines(1);/*  w ww .ja v a  2s.  c  o m*/
    input.setSingleLine(true);
    alert.setView(input, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String result = input.getText().toString();
            if (!result.isEmpty()) {
                saveLocation(result);
            }
        }
    });
    alert.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Cancelled
        }
    });
    alert.show();

}

From source file:com.normsstuff.maps4norm.Dialogs.java

/**
 * @param c the Context//from w  w w  . j  a v a2  s  . co m
 * @return a dialog allowing the user to gain access to the evelation
 * feature
 */
/*    
    public static Dialog getElevationAccessDialog(final Map c, final IInAppBillingService service) {
AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setMessage(R.string.buy_pro);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(final DialogInterface dialog, int which) {
        try {
            Bundle buyIntentBundle = service.getBuyIntent(3, c.getPackageName(),
                    "de.j4velin.mapsmeasure.billing.pro", "inapp", c.getPackageName());
            if (buyIntentBundle.getInt("RESPONSE_CODE") == 0) {
                PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                c.startIntentSenderForResult(pendingIntent.getIntentSender(), 42, null, 0,
                        0, 0);
            }
        } catch (Exception e) {
            Toast.makeText(c, e.getClass().getName() + ": " + e.getMessage(),
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
        dialog.dismiss();
    }
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(final DialogInterface dialog, int which) {
        dialog.dismiss();
    }
});
return builder.create();
    }
*/
public static Dialog getSearchDialog(final MyMapActivity map) {
    AlertDialog.Builder builder = new AlertDialog.Builder(map);
    final EditText search = new EditText(map);
    search.setHint(android.R.string.search_go);
    builder.setView(search);
    builder.setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, int which) {
            new GeocoderTask(map).execute(search.getText().toString());
            // hide softinput keyboard
            InputMethodManager inputManager = (InputMethodManager) map
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(search.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            dialog.dismiss();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, int which) {
            // hide softinput keyboard
            InputMethodManager inputManager = (InputMethodManager) map
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(search.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            dialog.dismiss();
        }
    });
    return builder.create();
}

From source file:jp.watnow.plugins.dialog.Notification.java

/**
 * /*w w  w  .  j  ava 2  s .c  om*/
 * @param message
 * @param title
 * @param buttonLabels
 * @param defaultTexts
 * @param callbackContext
 */
public synchronized void login(final String title, final String message, final JSONArray buttonLabels,
        final JSONArray defaultTexts, final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {
            LinearLayout layout = new LinearLayout(cordova.getActivity());
            layout.setOrientation(LinearLayout.VERTICAL);
            layout.setPadding(10, 0, 10, 0);
            final EditText usernameInput = new EditText(cordova.getActivity());
            usernameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
            final EditText passwordInput = new EditText(cordova.getActivity());
            passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            try {
                usernameInput.setHint("ID");
                usernameInput.setText(defaultTexts.getString(0));
                passwordInput.setHint("PASSWORD");
                passwordInput.setText(defaultTexts.getString(1));
            } catch (JSONException e1) {
            }

            layout.addView(usernameInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            layout.addView(passwordInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));

            AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            dlg.setView(layout);

            final JSONObject result = new JSONObject();

            try {
                dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        try {
                            result.put("buttonIndex", 1);
                            result.put("input1", usernameInput.getText());
                            result.put("input2", passwordInput.getText());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                    }
                });
            } catch (JSONException e) {
            }

            try {
                dlg.setPositiveButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        try {
                            result.put("buttonIndex", 3);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                    }
                });
            } catch (JSONException e) {
            }

            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    try {
                        result.put("buttonIndex", 0);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                }
            });

            changeTextDirection(dlg);
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.ichi2.anki.ModelBrowser.java

private void renameModelDialog() {
    try {/*from  www  .  j  ava2 s. c  o m*/
        mModelNameInput = new EditText(this);
        mModelNameInput.setSingleLine(true);
        mModelNameInput.setText(mModels.get(mModelListPosition).getString("name"));
        mModelNameInput.setSelection(mModelNameInput.getText().length());
        new MaterialDialog.Builder(this).title(R.string.rename_model).positiveText(R.string.dialog_ok)
                .customView(mModelNameInput, true).callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        JSONObject model = mModels.get(mModelListPosition);
                        String deckName = mModelNameInput.getText().toString()
                                .replaceAll("[\'\"\\n\\r\\[\\]\\(\\)]", "");
                        getCol().getDecks().id(deckName, true);
                        if (deckName.length() > 0) {
                            try {
                                model.put("name", deckName);
                                col.getModels().update(model);
                                mModels.get(mModelListPosition).put("name", deckName);
                                mModelDisplayList.set(mModelListPosition,
                                        new DisplayPair(mModels.get(mModelListPosition).getString("name"),
                                                mCardCounts.get(mModelListPosition)));
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            refreshList();
                        } else {
                            showToast(getResources().getString(R.string.toast_empty_name));
                        }
                    }
                }).show();
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.grass.caishi.cc.activity.SettingUserActivity.java

/**
 * /*from  w  w  w.ja v a 2 s. c om*/
 */
public void change_nickname(String nickname) {

    final EditText texta = new EditText(this);
    texta.setText(nickname);
    new AlertDialog.Builder(this).setTitle("").setIcon(android.R.drawable.ic_dialog_info)
            .setView(texta).setPositiveButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogg, int which) {
                    String nickname = texta.getEditableText().toString();
                    RequestParams params = new RequestParams();

                    params.add("nick", nickname);
                    params.add("type", "nick");
                    HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler);
                    dialog.show();
                    dialogg.dismiss();
                    // ?
                }
            }).setNegativeButton("?", null).show();
    // return true;
}

From source file:com.nttec.everychan.ui.NewTabFragment.java

private void openChansList() {
    final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) {
        private LayoutInflater inflater = LayoutInflater.from(activity);
        private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f);

        {//from   www  . j a  v a  2 s  . com
            for (ChanModule chan : MainApplication.getInstance().chanModulesList)
                add(chan);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ChanModule chan = getItem(position);
            TextView view = (TextView) (convertView == null
                    ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
                    : convertView);
            view.setText(chan.getDisplayingName());
            view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null);
            view.setCompoundDrawablePadding(drawablePadding);
            return view;
        }
    };

    DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ChanModule chan = chansAdapter.getItem(which);
            UrlPageModel model = new UrlPageModel();
            model.chanName = chan.getChanName();
            model.type = UrlPageModel.TYPE_INDEXPAGE;
            openNewTab(chan.buildUrl(model));
        }
    };

    final AlertDialog chansListDialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected)
            .setNegativeButton(android.R.string.cancel, null).create();

    chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() {
                @SuppressLint("InlinedApi")
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final ChanModule chan = chansAdapter
                            .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position);
                    switch (item.getItemId()) {
                    case R.id.context_menu_favorites_from_fragment:
                        if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null,
                                null)) {
                            MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null,
                                    null, null);
                        } else {
                            try {
                                UrlPageModel indexPage = new UrlPageModel();
                                indexPage.chanName = chan.getChanName();
                                indexPage.type = UrlPageModel.TYPE_INDEXPAGE;
                                MainApplication.getInstance().database.addFavorite(chan.getChanName(), null,
                                        null, null, chan.getChanName(), chan.buildUrl(indexPage));
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }
                        return true;
                    case R.id.context_menu_quickaccess_add:
                        QuickAccess.Entry newEntry = new QuickAccess.Entry();
                        newEntry.chan = chan;
                        list.add(0, newEntry);
                        adapter.notifyDataSetChanged();
                        saveQuickAccessToPreferences();
                        chansListDialog.dismiss();
                        return true;
                    case R.id.context_menu_quickaccess_custom_board:
                        LinearLayout dialogLayout = new LinearLayout(activity);
                        dialogLayout.setOrientation(LinearLayout.VERTICAL);
                        final EditText boardField = new EditText(activity);
                        final EditText descriptionField = new EditText(activity);
                        boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode);
                        descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc);
                        LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                        dialogLayout.addView(boardField, fieldsParams);
                        dialogLayout.addView(descriptionField, fieldsParams);
                        DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String boardName = boardField.getText().toString();
                                for (QuickAccess.Entry entry : list)
                                    if (entry.boardName != null && entry.chan != null)
                                        if (entry.chan.getChanName().equals(chan.getChanName())
                                                && entry.boardName.equals(boardName)) {
                                            Toast.makeText(activity,
                                                    R.string.newtab_quickaccess_addcustom_already_exists,
                                                    Toast.LENGTH_LONG).show();
                                            return;
                                        }

                                try {
                                    if (boardName.trim().length() == 0)
                                        throw new Exception();
                                    UrlPageModel boardPageModel = new UrlPageModel();
                                    boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE;
                                    boardPageModel.chanName = chan.getChanName();
                                    boardPageModel.boardName = boardName;
                                    boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
                                    chan.buildUrl(boardPageModel); //,  ??  ?    
                                } catch (Exception e) {
                                    Toast.makeText(activity,
                                            R.string.newtab_quickaccess_addcustom_incorrect_code,
                                            Toast.LENGTH_LONG).show();
                                    return;
                                }

                                QuickAccess.Entry newEntry = new QuickAccess.Entry();
                                newEntry.chan = chan;
                                newEntry.boardName = boardName;
                                newEntry.boardDescription = descriptionField.getText().toString();
                                list.add(0, newEntry);
                                adapter.notifyDataSetChanged();
                                saveQuickAccessToPreferences();
                                chansListDialog.dismiss();
                            }
                        };
                        new AlertDialog.Builder(activity)
                                .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title,
                                        chan.getChanName()))
                                .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked)
                                .setNegativeButton(android.R.string.cancel, null).show();
                        return true;
                    }
                    return false;
                }
            };
            String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)
                    .getChanName();
            boolean canAddToQuickAccess = true;
            for (QuickAccess.Entry entry : list)
                if (entry.boardName == null && entry.chan != null
                        && entry.chan.getChanName().equals(thisChanName)) {
                    canAddToQuickAccess = false;
                    break;
                }
            menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1,
                    MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null)
                            ? R.string.context_menu_remove_favorites
                            : R.string.context_menu_add_favorites)
                    .setOnMenuItemClickListener(contextMenuHandler);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add)
                    .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3,
                    R.string.context_menu_quickaccess_custom_board)
                    .setOnMenuItemClickListener(contextMenuHandler);
            if (isSingleboardChan(
                    chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)))
                menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false);
        }
    });
    chansListDialog.show();
}

From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java

void savePlaylist(final String name) {
    if (name.equals(getResources().getString(R.string.newPlaylist))) {
        // if "new playlist", show dialog with EditText for new playlist:
        final EditText input = new EditText(mActivity);
        new AlertDialog.Builder(mActivity).setTitle(R.string.newPlaylistPrompt).setView(input)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override//from  w  w w. j a v  a  2 s  . c  o m
                    public void onClick(final DialogInterface dialog, final int which) {
                        final String name = input.getText().toString().trim();
                        if (!name.isEmpty() && !name.equals(MPD.STREAMS_PLAYLIST)) {
                            // TODO: Need to warn user if they attempt to save to MPD.STREAMS_PLAYLIST
                            savePlaylist(name);
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        // Do nothing.
                    }
                }).create().show();
    } else if (!name.isEmpty()) {
        // actually save:
        QueueControl.run(QueueControl.SAVE_PLAYLIST, name);
    }
}

From source file:com.dirkgassen.wator.ui.view.RangeSlider.java

/**
 * Allows the user to click on the thumb. Clicking shows an alert that allows the user to enter a value. The
 * entered value is adjusted to the minimum/maximum (or to be one of the value set if one is active).
 *
 * @return {@code true} to indicate that the click was handled.
 *//*w w w  .  ja  v a  2 s. c  o  m*/
@Override
public boolean performClick() {
    super.performClick();

    final Context c = this.getContext();
    final AlertDialog.Builder alert = new AlertDialog.Builder(c);
    final EditText input = new EditText(c);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    input.setEms(getMaxDigits());
    alert.setView(input).setTitle(getContext().getString(R.string.enter_new_value_title))
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    try {
                        int enteredValue = Integer.valueOf(input.getText().toString().trim());
                        int newValue;
                        if (valueSet != null) {
                            newValue = valueSet[valueSet.length - 1];
                            for (int searchValue : valueSet) {
                                if (enteredValue <= searchValue) {
                                    newValue = searchValue;
                                    break;
                                }
                            }
                        } else {
                            newValue = enteredValue < minValue ? minValue
                                    : enteredValue > maxValue ? maxValue : enteredValue;
                        }
                        if (newValue != enteredValue) {
                            Toast.makeText(c, c.getString(R.string.entered_value_adjusted, newValue),
                                    Toast.LENGTH_LONG).show();
                        }
                        if (newValue != value) {
                            updateValue(newValue, true /* from user */);
                        }
                    } catch (NumberFormatException e) {
                        Toast.makeText(c, R.string.invalid_value, Toast.LENGTH_SHORT).show();
                    }
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            }).show();

    return true;
}

From source file:com.example.android.contactslist.ui.groupsEditor.GroupsEditorFragment.java

private void specifyNewGroupToAdd() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.dialog_title_enter_group_name);

    // Set up the input
    final EditText input = new EditText(getActivity());

    // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
    input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    builder.setView(input);// ww w.j a  v  a2 s  .  com

    // Set up the buttons
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final GoogleGroupMaker googleGroupMaker = new GoogleGroupMaker(getActivity());

            name_of_new_group = input.getText().toString();

            // create new group with the given name
            googleGroupMaker.makeContactGroup(name_of_new_group);

        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}