List of usage examples for android.text Selection setSelection
public static final void setSelection(Spannable text, int index)
index
. From source file:Main.java
public static void setEditCursor(EditText editText) { CharSequence text = editText.getText(); //Debug.asserts(text instanceof Spannable); if (text instanceof Spannable) { Spannable spanText = (Spannable) text; Selection.setSelection(spanText, text.length()); }/*from w w w. j av a2 s . c o m*/ }
From source file:Main.java
public static void setCursorLocation(Context context, EditText editText) { CharSequence text = editText.getText(); if (text instanceof Spannable) { Spannable spanText = (Spannable) text; Selection.setSelection(spanText, text.length()); }//from w w w. jav a 2s . co m }
From source file:Main.java
public static void setEditTextCursorLocation(EditText editText) { CharSequence text = editText.getText(); if (text instanceof Spannable) { Spannable spanText = (Spannable) text; Selection.setSelection(spanText, text.length()); }// w w w . ja v a2 s .c o m }
From source file:Main.java
public static final void setEditTextSelectionToEnd(EditText editText) { Editable editable = editText.getEditableText(); Selection.setSelection((Spannable) editable, editable.toString().length()); }
From source file:me.panpf.tool4a.util.InputMethodUtils.java
/** * ?// w w w.j a v a2 s .com */ @SuppressWarnings("WeakerAccess") public static void moveCursorToEnd(EditText editText) { Editable editable = editText.getEditableText(); Selection.setSelection(editable, editable.toString().length()); }
From source file:cn.foxnickel.listentome.view.ViewUtil.java
/** * /* w w w . jav a 2s . c o m*/ */ public static final void setEditTextSelectionToEnd(EditText editText) { Editable editable = editText.getEditableText(); Selection.setSelection((Spannable) editable, editable.toString().length()); }
From source file:org.odk.collect.android.widgets.StringWidget.java
protected StringWidget(Context context, FormEntryPrompt prompt, boolean readOnlyOverride, boolean derived) { super(context, prompt); answerText = new EditText(context); answerText.setId(ViewIds.generateViewId()); readOnly = prompt.isReadOnly() || readOnlyOverride; answerText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, answerFontsize); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); /*/*from w ww . jav a 2s. c o m*/ * If a 'rows' attribute is on the input tag, set the minimum number of lines * to display in the field to that value. * * I.e., * <input ref="foo" rows="5"> * ... * </input> * * will set the height of the EditText box to 5 rows high. */ String height = prompt.getQuestion().getAdditionalAttribute(null, ROWS); if (height != null && height.length() != 0) { try { int rows = Integer.parseInt(height); answerText.setMinLines(rows); answerText.setGravity(Gravity.TOP); // to write test starting at the top of the edit area } catch (Exception e) { Timber.e("Unable to process the rows setting for the answerText field: %s", e.toString()); } } params.setMargins(7, 5, 7, 5); answerText.setLayoutParams(params); // capitalize the first letter of the sentence answerText.setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false)); // needed to make long read only text scroll answerText.setHorizontallyScrolling(false); answerText.setSingleLine(false); String s = prompt.getAnswerText(); if (s != null) { answerText.setText(s); Selection.setSelection(answerText.getText(), answerText.getText().toString().length()); } if (readOnly) { answerText.setBackground(null); answerText.setEnabled(false); answerText.setTextColor(ContextCompat.getColor(context, R.color.primaryTextColor)); answerText.setFocusable(false); } addAnswerView(answerText); }
From source file:com.insthub.O2OMobile.Activity.C15_EditPriceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.c15_edit_price); mMyService = (MY_SERVICE) getIntent().getSerializableExtra(SERVICE); nTitle = (TextView) findViewById(R.id.top_view_title); nTitle.setText(getString(R.string.modify_service)); mBack = (ImageView) findViewById(R.id.top_view_back); mType = (TextView) findViewById(R.id.service_type); mPrice = (EditText) findViewById(R.id.price); mSave = (Button) findViewById(R.id.save); if (mMyService != null) { mType.setText(mMyService.service_type.title); mPrice.setText(mMyService.price); mPrice.setSelection(mMyService.price.length()); }//from w ww . ja va2 s . co m mServiceModel = new ServiceModel(this); mServiceModel.addResponseListener(this); mSave.setOnClickListener(this); mBack.setOnClickListener(this); mPrice.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (s.toString().length() > 0) { if (s.toString().substring(0, 1).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); } } if (s.toString().length() > 1) { if (s.toString().substring(0, 1).equals("0")) { if (!s.toString().substring(1, 2).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } boolean flag = false; for (int i = 0; i < s.toString().length() - 1; i++) { String getstr = s.toString().substring(i, i + 1); if (getstr.equals(".")) { flag = true; break; } } if (flag) { int i = s.toString().indexOf("."); if (s.toString().length() - 3 > i) { String getstr = s.toString().substring(0, i + 3); mPrice.setText(getstr); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); }
From source file:org.thoughtcrime.securesms.scribbles.widget.MotionView.java
public void startEditing(TextEntity entity) { editText.setFocusableInTouchMode(true); editText.setFocusable(true);/*from w w w . ja va2s. c o m*/ editText.requestFocus(); editText.setText(entity.getLayer().getText()); Selection.setSelection(editText.getText(), editText.length()); InputMethodManager ims = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); ims.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); }
From source file:com.fenlisproject.elf.core.widget.ExtendedEditText.java
/** * Convenience for {@link Selection#setSelection(Spannable, int)}. */ public void setSelection(int index) { Selection.setSelection(getText(), index); }