List of usage examples for android.widget EditText setSelection
public void setSelection(int index)
From source file:de.baumann.hhsmoodle.helper.helper_main.java
public static void showKeyboard(final Activity activity, final EditText editText) { new Handler().postDelayed(new Runnable() { public void run() { InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); editText.setSelection(editText.length()); }/*from w ww. j ava 2 s . co m*/ }, 200); }
From source file:com.cw.litenote.tabs.TabsHost.java
/** * edit page title/*from w w w . ja v a2 s . c o m*/ * */ static void editPageTitle(final int tabPos, final AppCompatActivity act) { final DB_folder mDbFolder = mTabsPagerAdapter.dbFolder; // get tab name String title = mDbFolder.getPageTitle(tabPos, true); final EditText editText1 = new EditText(act.getBaseContext()); editText1.setText(title); editText1.setSelection(title.length()); // set edit text start position editText1.setTextColor(Color.BLACK); //update tab info AlertDialog.Builder builder = new AlertDialog.Builder(act); builder.setTitle(R.string.edit_page_tab_title).setMessage(R.string.edit_page_tab_message).setView(editText1) .setNegativeButton(R.string.btn_Cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /*cancel*/} }).setNeutralButton(R.string.edit_page_button_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // delete Util util = new Util(act); util.vibrate(); AlertDialog.Builder builder1 = new AlertDialog.Builder(act); builder1.setTitle(R.string.confirm_dialog_title) .setMessage(R.string.confirm_dialog_message_page) .setNegativeButton(R.string.confirm_dialog_button_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog1, int which1) { /*nothing to do*/} }) .setPositiveButton(R.string.confirm_dialog_button_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog1, int which1) { deletePage(tabPos, act); FolderUi.selectFolder(act, FolderUi.getFocus_folderPos()); } }) .show(); } }).setPositiveButton(R.string.edit_page_button_update, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // save final int pageId = mDbFolder.getPageId(tabPos, true); final int pageTableId = mDbFolder.getPageTableId(tabPos, true); int tabStyle = mDbFolder.getPageStyle(tabPos, true); mDbFolder.updatePage(pageId, editText1.getText().toString(), pageTableId, tabStyle, true); FolderUi.startTabsHostRun(); } }).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: color ((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); }
From source file:Main.java
public static void uppercaseEditText(final EditText editText) { editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); editText.addTextChangedListener(new TextWatcher() { @Override//from ww w.j a v a2 s .c o m public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void afterTextChanged(Editable arg0) { String s = arg0.toString(); if (!s.equals(s.toUpperCase().trim())) { s = s.toUpperCase().trim(); editText.setText(s); editText.setSelection(s.length()); } } }); }
From source file:it.mb.whatshare.Dialogs.java
/** * Shows a dialog to get a name for the inbound device being paired and * starts a new {@link CallGooGlInbound} action if the chosen name is valid. * //from ww w . ja v a 2 s .c om * @param deviceType * the model of the device being paired as suggested by the * device itself * @param sharedSecret * the keys used when encrypting the message between devices * @param activity * the caller activity */ public static void promptForInboundName(final String deviceType, final int[] sharedSecret, final MainActivity activity) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { DialogFragment prompt = new PatchedDialogFragment() { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = getBuilder(activity); final EditText input = new EditText(getContext()); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setText(deviceType); input.setSelection(deviceType.length()); // @formatter:off builder.setTitle(R.string.device_name_chooser_title).setView(input) .setPositiveButton(android.R.string.ok, null); // @formatter:on final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener( new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() { @Override public void run() { // @formatter:off new CallGooGlInbound(activity, getParam(), deviceType) .execute(sharedSecret); ((InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); // @formatter:on } })); return alertDialog; } }; prompt.show(activity.getSupportFragmentManager(), "chooseName"); } }); }
From source file:it.mb.whatshare.Dialogs.java
/** * Shows a prompt to the user to rename the argument <tt>device</tt>. * /*from ww w . j a va 2 s. c om*/ * @param device * the device to be renamed * @param activity * the parent activity */ public static void promptForNewDeviceName(final PairedDevice device, final MainActivity activity) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { DialogFragment prompt = new PatchedDialogFragment() { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = getBuilder(activity); final EditText input = new EditText(getContext()); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setText(device.name); input.setSelection(device.name.length()); // @formatter:off builder.setTitle(R.string.device_name_chooser_title).setView(input) .setPositiveButton(android.R.string.ok, null); // @formatter:on final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener( new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() { @Override public void run() { // @formatter:off device.rename(getParam()); activity.onSelectedDeviceRenamed(); ((InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); // @formatter:on } })); return alertDialog; } }; prompt.show(activity.getSupportFragmentManager(), "chooseName"); } }); }
From source file:com.simplaapliko.trips.presentation.fragment.BaseFragment.java
protected void setCursorToEnd(EditText editText) { editText.setSelection(editText.getText().length()); }
From source file:at.alladin.rmbt.android.loopmode.LoopModeStartFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setTitle(R.string.preferences_category_loop_mode); final View v = inflater.inflate(R.layout.loop_mode_start_dialog, container, false); final int maxDelay = ConfigHelper.getLoopModeMaxDelay(getActivity()); final int maxMovement = ConfigHelper.getLoopModeMaxMovement(getActivity()); final String info = getString(R.string.loop_mode_info); TextView infoText = (TextView) v.findViewById(R.id.loop_mode_info); infoText.setText(MessageFormat.format(info, maxMovement, maxDelay)); final int maxTests = ConfigHelper.getLoopModeMaxTests(getActivity()); final EditText maxTestsEdit = (EditText) v.findViewById(R.id.loop_mode_max_tests); maxTestsEdit.setText(String.valueOf(maxTests)); maxTestsEdit.setSelection(String.valueOf(maxTests).length()); Button goButton = (Button) v.findViewById(R.id.loop_mode_start_button); goButton.setOnClickListener(new OnClickListener() { @Override/*from w ww .j a v a 2 s .c om*/ public void onClick(View v) { try { boolean startTest = true; if (!ConfigHelper.isDevEnabled(getActivity())) { startTest = RMBTPreferenceActivity.checkInputValidity(getActivity(), maxTestsEdit.getText().toString(), AppConstants.LOOP_MODE_MIN_TESTS, AppConstants.LOOP_MODE_MAX_TESTS, R.string.loop_mode_max_tests_invalid); } if (startTest) { LoopModeStartFragment.this.dismiss(); ConfigHelper.setLoopModeMaxTests(getActivity(), Integer.parseInt(maxTestsEdit.getText().toString())); ((RMBTMainActivity) getActivity()).startLoopTest(); } } catch (Exception e) { e.printStackTrace(); } } }); Button goToSettingsButton = (Button) v.findViewById(R.id.loop_mode_go_to_settings_button); goToSettingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { LoopModeStartFragment.this.dismiss(); ((RMBTMainActivity) getActivity()).showSettings(); } }); return v; }
From source file:org.mozilla.focus.fragment.AddToHomescreenDialogFragment.java
@NonNull @Override// w w w. j a v a 2 s . c o m public AlertDialog onCreateDialog(Bundle bundle) { final String url = getArguments().getString(URL); final String title = getArguments().getString(TITLE); final boolean blockingEnabled = getArguments().getBoolean(BLOCKING_ENABLED); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.DialogStyle); builder.setCancelable(true); builder.setTitle(getActivity().getString(R.string.menu_add_to_home_screen)); final LayoutInflater inflater = getActivity().getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.add_to_homescreen, null); builder.setView(dialogView); final Bitmap icon = IconGenerator.generateLauncherIcon(getActivity(), url); final Drawable d = new BitmapDrawable(getResources(), icon); final ImageView iconView = (ImageView) dialogView.findViewById(R.id.homescreen_icon); iconView.setImageDrawable(d); final ImageView blockIcon = (ImageView) dialogView.findViewById(R.id.homescreen_dialog_block_icon); blockIcon.setImageResource(R.drawable.ic_tracking_protection_16_disabled); final Button addToHomescreenDialogCancelButton = (Button) dialogView .findViewById(R.id.addtohomescreen_dialog_cancel); final Button addToHomescreenDialogConfirmButton = (Button) dialogView .findViewById(R.id.addtohomescreen_dialog_add); addToHomescreenDialogCancelButton.setText(getString(R.string.dialog_addtohomescreen_action_cancel)); addToHomescreenDialogConfirmButton.setText(getString(R.string.dialog_addtohomescreen_action_add)); final LinearLayout warning = (LinearLayout) dialogView.findViewById(R.id.homescreen_dialog_warning_layout); warning.setVisibility(blockingEnabled ? View.GONE : View.VISIBLE); final EditText editableTitle = (EditText) dialogView.findViewById(R.id.edit_title); if (!TextUtils.isEmpty(title)) { editableTitle.setText(title); editableTitle.setSelection(title.length()); } addToHomescreenDialogCancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TelemetryWrapper.cancelAddToHomescreenShortcutEvent(); dismiss(); } }); addToHomescreenDialogConfirmButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { HomeScreen.installShortCut(getActivity(), icon, url, editableTitle.getText().toString().trim(), blockingEnabled); TelemetryWrapper.addToHomescreenShortcutEvent(); dismiss(); } }); return builder.create(); }
From source file:com.ouyangzn.github.module.account.LoginFragment.java
/** * ??dialog//w w w. j a v a2 s. com * * @param onConfirmClick */ private void showInputUsernameDialog(View.OnClickListener onConfirmClick) { AlertDialog.Builder builder = DialogUtils.getAlertDialog(getContext()); AlertDialog dialog = builder.setView(R.layout.dialog_input_view).create(); dialog.show(); TextView tvTitle = ButterKnife.findById(dialog, R.id.tv_dialog_input_title); tvTitle.setText(R.string.username_github); EditText etUsername = ButterKnife.findById(dialog, R.id.et_dialog_input); String user = App.getUsername(); etUsername.setText(user); if (!TextUtils.isEmpty(user)) { etUsername.setSelection(user.length()); } Button btnConfirm = ButterKnife.findById(dialog, R.id.btn_dialog_input_confirm); btnConfirm.setTag(dialog); btnConfirm.setOnClickListener(v -> { ScreenUtils.hideKeyBoard(v); dialog.dismiss(); String username = etUsername.getText().toString().trim(); if (TextUtils.isEmpty(username)) { toast(R.string.error_username_null); return; } App.setUsername(username); if (onConfirmClick != null) onConfirmClick.onClick(v); }); Button btnCancel = ButterKnife.findById(dialog, R.id.btn_dialog_input_cancel); btnCancel.setTag(dialog); btnCancel.setOnClickListener(v -> { ScreenUtils.hideKeyBoard(v); dialog.dismiss(); }); }
From source file:org.leopub.mat.controller.ComposeActivity.java
private void addSingleReceiver(Contact contact) { String str = contact.getId() + "," + contact.getName() + ";"; mReceivers += str;//from w w w . j a v a 2s. co m EditText toView = (EditText) findViewById(R.id.compose_dst); toView.setText(mReceivers); toView.setSelection(mReceivers.length()); }