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.ichi2.anki.dialogs.CustomStudyDialog.java

/**
 * Build an input dialog that is used to get a parameter related to custom study from the user
 * @param dialogId/*from  ww w. j  a  v  a2s. co  m*/
 * @return
 */
private MaterialDialog buildInputDialog(final int dialogId) {
    /*
    TODO: Try to change to a standard input dialog (currently the thing holding us back is having the extra
    TODO: hint line for the number of cards available, and having the pre-filled text selected by default)
    */
    // Input dialogs
    Resources res = getActivity().getResources();
    // Show input dialog for an individual custom study dialog
    View v = getActivity().getLayoutInflater().inflate(R.layout.styled_custom_study_details_dialog, null);
    TextView textView1 = (TextView) v.findViewById(R.id.custom_study_details_text1);
    TextView textView2 = (TextView) v.findViewById(R.id.custom_study_details_text2);
    final EditText mEditText = (EditText) v.findViewById(R.id.custom_study_details_edittext2);
    // Set the text
    textView1.setText(getText1());
    textView2.setText(getText2());
    mEditText.setText(getDefaultValue());
    // Give EditText focus and show keyboard
    mEditText.setSelectAllOnFocus(true);
    mEditText.requestFocus();
    // deck id
    final long did = getArguments().getLong("did");
    // Whether or not to jump straight to the reviewer
    final boolean jumpToReviewer = getArguments().getBoolean("jumpToReviewer");
    // Set builder parameters
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).customView(v, true)
            .positiveText(res.getString(R.string.dialog_ok)).negativeText(res.getString(R.string.dialog_cancel))
            .callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    Collection col = CollectionHelper.getInstance().getCol(getActivity());
                    // Get the value selected by user
                    int n = Integer.parseInt(mEditText.getText().toString());
                    // Set behavior when clicking OK button
                    switch (dialogId) {
                    case CUSTOM_STUDY_NEW:
                        try {
                            AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n).commit();
                            JSONObject deck = col.getDecks().get(did);
                            deck.put("extendNew", n);
                            col.getDecks().save(deck);
                            col.getSched().extendLimits(n, 0);
                            onLimitsExtended(jumpToReviewer);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        break;
                    case CUSTOM_STUDY_REV:
                        try {
                            AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n).commit();
                            JSONObject deck = col.getDecks().get(did);
                            deck.put("extendRev", n);
                            col.getDecks().save(deck);
                            col.getSched().extendLimits(0, n);
                            onLimitsExtended(jumpToReviewer);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        break;
                    case CUSTOM_STUDY_FORGOT:
                        JSONArray ar = new JSONArray();
                        try {
                            ar.put(0, 1);
                            createCustomStudySession(ar,
                                    new Object[] { String.format(Locale.US, "rated:%d:1", n),
                                            Consts.DYN_MAX_SIZE, Consts.DYN_RANDOM },
                                    false);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        break;
                    case CUSTOM_STUDY_AHEAD:
                        createCustomStudySession(new JSONArray(),
                                new Object[] { String.format(Locale.US, "prop:due<=%d", n), Consts.DYN_MAX_SIZE,
                                        Consts.DYN_DUE },
                                true);
                        break;
                    case CUSTOM_STUDY_RANDOM:
                        createCustomStudySession(new JSONArray(), new Object[] { "", n, Consts.DYN_RANDOM },
                                true);
                        break;
                    case CUSTOM_STUDY_PREVIEW:
                        createCustomStudySession(new JSONArray(), new Object[] {
                                "is:new added:" + Integer.toString(n), Consts.DYN_MAX_SIZE, Consts.DYN_OLDEST },
                                false);
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                    ((AnkiActivity) getActivity()).dismissAllDialogFragments();
                }
            });
    final MaterialDialog dialog = builder.build();
    mEditText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (((EditText) view).getText().length() == 0) {
                dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
            } else {
                dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
            }
            return false;
        }
    });
    // Show soft keyboard
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return dialog;
}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_help:
        helper_main.switchToActivity(getActivity(), Random_Help.class, false);
        return true;

    case R.id.action_dice:
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                getActivity());//from w  ww.jav  a 2s.  co m
        View dialogView = View.inflate(getActivity(), R.layout.dialog_dice, null);

        final TextView textChoose2 = (TextView) dialogView.findViewById(R.id.textChoose);
        final EditText editNumber2 = (EditText) dialogView.findViewById(R.id.editNumber);
        editNumber2.setHint(R.string.number_dice_hint);

        builder.setView(dialogView);
        builder.setTitle(R.string.number_dice);
        builder.setPositiveButton(R.string.toast_yes, null);
        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        final android.support.v7.app.AlertDialog dialog2 = builder.create();
        // Display the custom alert dialog on interface
        dialog2.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {

                Button b = dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        try {
                            number = Integer.parseInt(editNumber2.getText().toString());
                            Random rand = new Random();
                            int n = rand.nextInt(number);
                            textChoose2.setText(String.valueOf(n + 1));
                        } catch (NumberFormatException nfe) {
                            Snackbar.make(textChoose2, R.string.number_dice_error, Snackbar.LENGTH_LONG).show();
                            nfe.printStackTrace();
                        }
                    }
                });
            }
        });

        dialog2.show();
        helper_main.showKeyboard(getActivity(), editNumber2);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

/**
 * Displays a "Rename" dialog and renames the specified file/folder.
 *
 * @param path The path of the folder/file that needs to be renamed.
 *//*w w  w.  ja v  a 2  s .co  m*/
public void rename(String path) {

    final File renameFile = new File(path);
    final AlertDialog renameAlertDialog = new AlertDialog.Builder(getActivity()).create();
    final EditText fileEditText = new EditText(getActivity());

    fileEditText.setHint(R.string.file_name);
    fileEditText.setSingleLine(true);
    fileEditText.setText(renameFile.getName());

    renameAlertDialog.setView(fileEditText);
    renameAlertDialog.setTitle(R.string.rename);
    renameAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
            mContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    renameAlertDialog.dismiss();
                }

            });

    renameAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
            mContext.getResources().getString(R.string.rename), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    //Check if the new file name is empty.
                    if (fileEditText.getText().toString().isEmpty()) {
                        Toast.makeText(getActivity(), R.string.enter_a_name_for_folder, Toast.LENGTH_LONG)
                                .show();
                    } else {

                        File newNameFile = null;
                        try {
                            newNameFile = new File(renameFile.getParentFile().getCanonicalPath() + "/"
                                    + fileEditText.getText().toString());
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed,
                                    Toast.LENGTH_LONG).show();
                            return;
                        }

                        try {
                            if (renameFile.isDirectory())
                                FileUtils.moveDirectory(renameFile, newNameFile);
                            else
                                FileUtils.moveFile(renameFile, newNameFile);

                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed,
                                    Toast.LENGTH_LONG).show();
                            return;
                        }

                        Toast.makeText(getActivity(), R.string.folder_renamed, Toast.LENGTH_SHORT).show();
                        renameAlertDialog.dismiss();
                        refreshListView();

                    }

                }

            });

    renameAlertDialog.show();

}

From source file:com.vkassin.mtrade.Common.java

public static void login(final Context ctx) {

    // ctx = Common.app_ctx;
    Common.connected = false;/*from  ww  w  . j  a  va  2 s .c  o m*/

    if (inLogin)
        return;

    inLogin = true;

    if (Common.mainActivity != null)
        Common.mainActivity.handler.sendMessage(
                Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG));

    // while(true) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.login_dialog);
    dialog.setTitle(R.string.LoginDialogTitle);
    dialog.setCancelable(false);

    final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit);
    final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit);
    final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1);
    final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2);
    final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2);

    String nam = myaccount.get("name");
    Common.oldName = nam;

    if (nam != null) {

        nametxt.setText(nam);
        passtxt.requestFocus();
    }

    Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister);
    customDialog_Register.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle1);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.VISIBLE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.GONE);
        }

    });

    Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1);
    customDialog_Register1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            if (mailtxt.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

                return;
            }

            if (passtxt1.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            try {

                Socket sock = new Socket(ip_addr, port_register);

                JSONObject msg = new JSONObject();
                msg.put("objType", Common.MSG_REGISTER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("user", mailtxt.getText().toString());
                msg.put("passwd", passtxt1.getText().toString());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString()));

                byte[] array = msg.toString().getBytes();
                ByteBuffer buff = ByteBuffer.allocate(array.length + 4);
                buff.putInt(array.length);
                buff.put(array);
                sock.getOutputStream().write(buff.array());

                ByteBuffer buff1 = ByteBuffer.allocate(4);
                buff1.put(readMsg(sock.getInputStream(), 4));
                buff1.position(0);
                int pkgSize = buff1.getInt();
                // Log.i(TAG, "size = "+pkgSize);
                String s = new String(readMsg(sock.getInputStream(), pkgSize));

                sock.close();

                JSONObject jo = new JSONObject(s);

                Log.i(TAG, "register answer = " + jo);

                int t = jo.getInt("status");
                switch (t) {

                case 1:
                    Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast.show();

                    dialog.setTitle(R.string.LoginDialogTitle);
                    final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
                    layreg.setVisibility(View.GONE);
                    final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
                    laylog.setVisibility(View.VISIBLE);

                    nametxt.setText(mailtxt.getText());
                    break;

                case -2:
                    Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG);
                    toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast1.show();
                    break;

                default:
                    Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG);
                    toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast2.show();
                    break;

                }

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error in registration process!!", e);

                Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

            }

        }

    });

    Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg);
    customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.GONE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.VISIBLE);

        }

    });

    Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin);
    customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0);
            Common.isSSL = bu0.isChecked();

            inLogin = false;

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.LOGOUT);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("status", 1);
                mainActivity.writeJSONMsg(msg);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON logout object", e);
            }

            myaccount.put("name", nametxt.getText().toString());
            myaccount.put("password", passtxt.getText().toString());

            Log.i(TAG,
                    "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password"));

            dialog.dismiss();
            mainActivity.stop();
            // saveAccountDetails();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            loginFromDialog = true;
            //            mainActivity.refresh();

            Common.keypassword(ctx);
        }

    });

    dialog.show();
    // Common.confChanged = false;
    // }//while(true);

}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ? // ww w  . j  a  va  2 s  .c  o  m
 */
private void showAddPop() {
    final EditText editText = new EditText(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editText.setLayoutParams(layoutParams);
    //        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint("?~");
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));
    editText.setBackgroundColor(getResources().getColor(android.R.color.black));
    final PopupWindow popupWindow = new PopupWindow(editText, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                ProgressDialogUtils.showProgressDialog();
                UnFinishItem item = new UnFinishItem();
                Date date = new Date();
                item.createDay = date;
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                dataList.add(item);
                refreshData(true);
                presenter.addItem(item);
            }
        }
    });
}

From source file:org.cryptsecure.Utility.java

/**
 * Smart paste some pasteText into an editText. Remember the position (i)
 * and jump behind the pastedText afterwards if not jumpToEnd is selected.
 * If selectAfterPaste is set then select the pasted text.
 * /*from  w  w w  . j a  v a  2s. c  o m*/
 * 
 * @param editText
 *            the edit text
 * @param pasteText
 *            the paste text
 * @param ensureBefore
 *            the ensure before
 * @param ensureAfter
 *            the ensure after
 * @param jumpToEnd
 *            the jump to end
 */
public static void smartPaste(EditText editText, String pasteText, String ensureBefore, String ensureAfter,
        boolean jumpToEnd, boolean selectAfterPaste, boolean ensureBeforeOnlyIfNotBeginning) {
    // messageText.getText().append(textualSmiley);
    // if text was selected replace the text
    int i = editText.getSelectionStart();
    int e = editText.getSelectionEnd();
    String prevText = editText.getText().toString();
    if (i < 0) {
        // default fallback is concatenation
        if (!prevText.endsWith(ensureBefore)) {
            if (!ensureBeforeOnlyIfNotBeginning || prevText.length() > 0) {
                prevText = prevText.concat(ensureBefore);
            }
        }
        editText.setText(prevText + pasteText + ensureAfter);
    } else {
        // otherwise try to fill in the text
        String text1 = prevText.substring(0, i);
        if (!text1.endsWith(ensureBefore)) {
            if (!ensureBeforeOnlyIfNotBeginning || prevText.length() > 0) {
                text1 = text1.concat(ensureBefore);
            }
        }
        if (e < 0) {
            e = i;
        }
        String text2 = prevText.substring(e);
        if (!text2.startsWith(ensureAfter)) {
            text2 = ensureAfter + text2;
        }
        editText.setText(text1.concat(pasteText).concat(text2));
    }
    if (selectAfterPaste) {
        editText.setSelection(i, i + pasteText.length());
    } else if (jumpToEnd) {
        editText.setSelection(editText.getText().length());
    } else {
        editText.setSelection(i);
    }
}

From source file:com.nextgis.mobile.map.LocalTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, int type,
        final Uri uri, final LocalTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);//from w w  w. j  av  a2  s  . c om

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_qtiles));
    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), tmsType, uri);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:com.kncwallet.wallet.ui.WalletActivity.java

private Dialog createExportKeysDialog() {
    final View view = getLayoutInflater().inflate(R.layout.export_keys_dialog, null);
    final EditText passwordView = (EditText) view.findViewById(R.id.export_keys_dialog_password);

    final KnCDialog.Builder builder = new KnCDialog.Builder(this);
    builder.setInverseBackgroundForced(true);
    builder.setTitle(R.string.export_keys_dialog_title);
    builder.setView(view);//from   www. ja va2 s.c  o  m
    builder.setPositiveButton(R.string.export_keys_dialog_button_export, new OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            final String password = passwordView.getText().toString().trim();
            passwordView.setText(null); // get rid of it asap

            exportPrivateKeys(password);
        }
    });
    builder.setNegativeButton(R.string.button_cancel, new OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            passwordView.setText(null); // get rid of it asap
        }
    });
    builder.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(final DialogInterface dialog) {
            passwordView.setText(null); // get rid of it asap
        }
    });

    final AlertDialog dialog = builder.create();

    return dialog;
}

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

private void editRepo(final String repo) {
    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.addrepo, null);
    Builder p = new AlertDialog.Builder(this).setView(view);
    final AlertDialog alrt = p.create();
    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);
    uri.setText(repo);/*w  ww .  j  av  a2 s .co m*/

    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);
            }
        }
    });

    String[] logins = null;
    logins = db.getLogin(repo);
    if (logins != null) {
        sec.setChecked(true);
        sec_user.setText(logins[0]);
        sec_pwd.setText(logins[1]);
    } else {
        sec.setChecked(false);
    }

    alrt.setIcon(android.R.drawable.ic_menu_add);
    alrt.setTitle("Edit repository");
    alrt.setButton("Done", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String new_repo = uri.getText().toString();
            db.updateServer(repo, new_repo);
            if (sec.isChecked()) {
                db.addLogin(sec_user.getText().toString(), sec_pwd.getText().toString(), new_repo);
            } else {
                db.disableLogin(new_repo);
            }
            change = true;
            redraw();
        }
    });

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