I understand this is an old post, but I had the same problem. For me, the argument was that I like to reset the keyboard (turn it off) to understand (or press buttons to add or delete data lines), and when I touched the EditText that I previously edited, it was unpleasant when the keyboard pop back and the text is not selected, forcing me to either work to hover over where I wanted to start deleting, or touch another EditText and then touch the original to re-select everything, I just want the keyboard to pop back, and the text is selected and ready to dub syaky time I come to the EditText.
There are simple solutions:
1) A long crane does this for you in most cases.
2) If you are already using setSelectAllOnFocus(true)
, you can simply skip the simple clearFocus()
and requestFocus()
in your onClick listener:
etMyEditText.setSelectAllOnFocus(true); etMyEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { view.clearFocus(); view.requestFocus(); } });
Thus, EditText has everything that was selected when you click on it, regardless of the state of the soft keyboard.
Extra bonus: Add android:windowSoftInputMode="adjustPan"
to your <activity .../>
in your AndroidManifest.xml file to force the selected EditText to appear when the soft keyboard appears.
source share