How To Select Text With A Single Click In The Edittext?
Source code below is not working public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activit
Solution 1:
Use this piece of code in your .java file:
editText.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
editText.setSelection(0, editText.getText().length() - 1);
}
}
Solution 2:
with xml:
android:selectAllOnFocus="true"
with code (option1):
yourEditText.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
});
And also try like this:
Call EditText.setSelectAllOnFocus(boolean selectAllOnFocus)
to select all text on focus.
Set a click listener to your EditText and in onClick call edittext.selectAll();
Solution 3:
editText.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
editText.performLongClick();
}
});
An EditText
's default long-click behaviour is to select the word that has been tapped, then drag the selection markers, so just call performLongClick()
in onClick()
.
Post a Comment for "How To Select Text With A Single Click In The Edittext?"