Example usage for android.widget EditText setSelection

List of usage examples for android.widget EditText setSelection

Introduction

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

Prototype

public void setSelection(int index) 

Source Link

Document

Convenience for Selection#setSelection(Spannable,int) .

Usage

From source file:Main.java

public static void setSeletionEnd(EditText editText) {
    editText.setSelection(editText.getText().length());
}

From source file:Main.java

public static void putCursorAfterLastSymbol(EditText... editTexts) {
    for (EditText editText : editTexts) {
        editText.setSelection(editText.getText().length());
    }/*from   w  ww  .ja  v  a 2s  .  c om*/
}

From source file:Main.java

public static void setEnd(EditText et) {
    if (!isEmpty(et)) {
        et.setSelection(getString(et).length());
    }
}

From source file:Main.java

public static void setCursorAtTheEnd(EditText editText) {
    try {/*from  ww w .  jav  a 2s  .  co  m*/
        if (editText != null) {
            editText.setSelection(editText.getText().length());
        }
    } catch (Exception ex) {
    }
}

From source file:Main.java

public static void openKeyboard(final Context context, final EditText editText) {
    new Handler().postDelayed(new Runnable() {
        @Override/* w w w .java2s  . c  o m*/
        public void run() {
            editText.requestFocus();
            editText.setSelection(editText.getText().toString().length());
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
        }
    }, 300);
}

From source file:Main.java

public static void locateCursur(final EditText text) {
    if (text == null) {
        return;//from  www .j  a  v  a  2s.  c o m
    }
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Editable b = text.getText();
            text.setSelection(b.length());
        }
    }, 100);
}

From source file:de.baumann.quitsmoking.helper.helper_main.java

public static void showKeyboard(Activity from, EditText editText) {
    InputMethodManager imm = (InputMethodManager) from.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    editText.setSelection(editText.length());
}

From source file:com.madgag.agit.CloneLauncherActivity.java

private static void setCursorToEnd(EditText editText) {
    editText.setSelection(editText.getText().length());
}

From source file:com.hellofyc.base.util.ViewUtils.java

/**
 * ???// w  w w. j a v a 2s  . c om
 */
public static void setPasswordVisibility(@NonNull EditText input, boolean visibility) {
    if (visibility) {
        input.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        input.setSelection(input.length());
    } else {
        input.setTransformationMethod(PasswordTransformationMethod.getInstance());
        input.setSelection(input.length());
    }
}

From source file:com.cw.litenote.folder.FolderUi.java

static void editFolder(final AppCompatActivity act, final int position,
        final SimpleDragSortCursorAdapter folderAdapter) {
    DB_drawer db = new DB_drawer(act);

    // insert when table is empty, activated only for the first time
    final String folderTitle = db.getFolderTitle(position, true);

    final EditText editText = new EditText(act);
    editText.setText(folderTitle);//from  w w w  .  j a  v  a2 s . com
    editText.setSelection(folderTitle.length()); // set edit text start position

    //update tab info
    Builder builder = new Builder(act);
    builder.setTitle(R.string.edit_folder_title).setMessage(R.string.edit_folder_message).setView(editText)
            .setNegativeButton(R.string.btn_Cancel, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    /*cancel*/}
            }).setNeutralButton(R.string.edit_page_button_delete, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // delete
                    Util util = new Util(act);
                    util.vibrate();

                    Builder builder1 = new Builder(act);
                    builder1.setTitle(R.string.confirm_dialog_title)
                            .setMessage(R.string.confirm_dialog_message_folder)
                            .setNegativeButton(R.string.confirm_dialog_button_no, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog1, int which1) {
                                    /*nothing to do*/}
                            }).setPositiveButton(R.string.confirm_dialog_button_yes, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog1, int which1) {
                                    deleteFolder(act, position, folderAdapter);
                                }
                            }).show();
                }
            }).setPositiveButton(R.string.edit_page_button_update, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    DB_drawer db_drawer = new DB_drawer(act);
                    // save
                    int drawerId = (int) db_drawer.getFolderId(position, true);
                    int drawerTabInfoTableId = db_drawer.getFolderTableId(position, true);
                    db_drawer.updateFolder(drawerId, drawerTabInfoTableId, editText.getText().toString(), true);
                    // update
                    folderAdapter.notifyDataSetChanged();
                    act.getSupportActionBar().setTitle(editText.getText().toString());

                }
            }).setIcon(android.R.drawable.ic_menu_edit);

    AlertDialog d1 = builder.create();
    d1.show();
    // android.R.id.button1 for positive: save
    ((Button) d1.findViewById(android.R.id.button1))
            .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_menu_save, 0, 0, 0);

    // android.R.id.button2 for negative: cancel
    ((Button) d1.findViewById(android.R.id.button2))
            .setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_close_clear_cancel, 0, 0, 0);

    // android.R.id.button3 for neutral: delete
    ((Button) d1.findViewById(android.R.id.button3))
            .setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_delete, 0, 0, 0);
}