android:windowSoftInputMode="stateAlwaysVisible" -> in manifest File. edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears.
We have used getText() method to get the text entered in the EditText views.
android:ems is the number of 'M' occurrences in a EditText field. it points to its width.
You can try in your main.xml
file:
android:selectAllOnFocus="true"
Or, in Java, use
editText.setSelectAllOnFocus(true);
editText.setSelectAllOnFocus(true);
This works if you want to do it programatically.
EditText dummy = ...
// android.view.View.OnFocusChangeListener
dummy.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus) && (isDummyText())
((EditText)v).selectAll();
}
});
I know you've found a solution, but really the proper way to do what you're asking is to just use the android:hint
attribute in your EditText. This text shows up when the box is empty and not focused, but disappears upon selecting the EditText box.
Managed it by calling focus and selection on program
{
editabletext.requestFocus();
editabletext.selectAll();
}
Why don't you try android:hint="hint" to provide the hint to the user..!!
The "hint" will automatically disappear when the user clicks on the edittextbox. its the proper and best solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With