List of usage examples for android.widget EditText setSelection
public void setSelection(int index)
From source file:org.leopub.mat.controller.ComposeActivity.java
private void addUnitReceiver(String unitExpr) { String str = unitExpr + "," + mUser.getUnitTitle(unitExpr) + ";"; mReceivers += str;/*from w w w . j a va 2 s . c om*/ EditText toView = (EditText) findViewById(R.id.compose_dst); toView.setText(mReceivers); toView.setSelection(mReceivers.length()); }
From source file:org.adaway.ui.hosts.HostsSourcesFragment.java
/** * Add a hosts source./*w w w.ja va 2 s .c om*/ */ private void addSource() { // Create dialog builder AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle(R.string.hosts_add_dialog_title); builder.setCancelable(true); // Create dialog view LayoutInflater factory = LayoutInflater.from(mActivity); View view = factory.inflate(R.layout.hosts_sources_dialog, null); builder.setView(view); // Move cursor to end of EditText EditText inputEditText = view.findViewById(R.id.hosts_add_dialog_url); Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); // Setup buttons builder.setPositiveButton(R.string.button_add, (dialog, which) -> { String url = inputEditText.getText().toString(); if (HostsSource.isValidUrl(url)) { // Insert hosts source into database this.mViewModel.addSourceFromUrl(url); } dialog.dismiss(); }); builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> dialog.dismiss()); // Display dialog AlertDialog alertDialog = builder.create(); alertDialog.show(); // Set button validation behavior inputEditText.addTextChangedListener(new AlertDialogValidator(alertDialog, HostsSource::isValidUrl, false)); }
From source file:com.android.nsboc.ComposeFragment.java
private void showCurrentDateInEditText() { EditText dateField = (EditText) mRootView.findViewById(R.id.date); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); dateField.setText(formatter.format(new Date())); dateField.setSelection(dateField.length()); }
From source file:org.adaway.ui.hosts.HostsSourcesFragment.java
/** * Edit selected hosts source./*from w ww . j a v a 2 s. c o m*/ */ private void editSource() { // Check action source if (this.mActionSource == null) { return; } HostsSource editedSource = this.mActionSource; // Create dialog builder AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle(R.string.hosts_edit_dialog_title); builder.setCancelable(true); // Create dialog view LayoutInflater factory = LayoutInflater.from(mActivity); View view = factory.inflate(R.layout.hosts_sources_dialog, null); builder.setView(view); // Set source URL EditText inputEditText = view.findViewById(R.id.hosts_add_dialog_url); inputEditText.setText(editedSource.getUrl()); // Move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); // Setup buttons builder.setPositiveButton(getResources().getString(R.string.button_save), (dialog, which) -> { // Close dialog dialog.dismiss(); // Finish action mode HostsSourcesFragment.this.mActionMode.finish(); // Check url validity String url = inputEditText.getText().toString(); if (HostsSource.isValidUrl(url)) { // Update hosts source into database this.mViewModel.updateSourceUrl(editedSource, url); } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), (dialog, which) -> { // Close dialog dialog.dismiss(); // Finish action mode HostsSourcesFragment.this.mActionMode.finish(); }); AlertDialog alertDialog = builder.create(); alertDialog.show(); // Set button validation behavior inputEditText.addTextChangedListener(new AlertDialogValidator(alertDialog, HostsSource::isValidUrl, true)); }
From source file:org.adaway.ui.BlacklistFragment.java
/** * Add Entry Menu Action/*from w w w .j a v a2s. co m*/ */ public void menuAddEntry() { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_add_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_add), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); addEntry(input); } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adaway.ui.WhitelistFragment.java
/** * Add Entry Menu Action// ww w. j a v a 2s . c o m */ public void menuAddEntry() { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_add_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_add), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); addEntry(input); } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:sssemil.com.hostsaway.ui.BlacklistFragment.java
/** * Edit entry based on selection in context menu * * @param info//from ww w . j av a 2 s. c o m */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidHostname(input)) { ProviderHelper.updateBlacklistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:sssemil.com.hostsaway.ui.WhitelistFragment.java
/** * Edit entry based on selection in context menu * * @param info/*from w w w .ja v a 2 s . co m*/ */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidWhitelistHostname(input)) { ProviderHelper.updateWhitelistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adaway.ui.BlacklistFragment.java
/** * Edit entry based on selection in context menu * /* w w w .j ava 2 s. c o m*/ * @param info */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidHostname(input)) { ProviderHelper.updateBlacklistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(org.adaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adaway.ui.WhitelistFragment.java
/** * Edit entry based on selection in context menu * * @param info//from w ww.j ava2s . co m */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidWhitelistHostname(input)) { ProviderHelper.updateWhitelistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(org.adaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }