Reputation: 5770
I have an editText that I want to fill in automatically with info from other controls in the form, and at the same time allow to change its contents, discouraging the user from doing so though.
So I set this control to not focusable so when you press actionNext it moves on to the next control. However if you click the edit text, I want to allow the user to change its contents.
This is what I did:
mNameEditText.setFocusable(false);
mNameEditText.setFocusableInTouchMode(false);
mNameEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mNameEditText.setFocusableInTouchMode(true);
mNameEditText.requestFocusFromTouch();
mNameEditText.setFocusable(true);
}
});
However this behaves very weirdly, the result is that when you click, you can edit, but suddenly the next control (an AutoCompleteTextView) is not focusable anymore! Actually it looks like the focus remains on the edit text and goes to the autocompletetextview at the same time, like so:
How can I fix this?
Upvotes: 7
Views: 694
Reputation: 17735
If you want the automatic focus change to skip some views, you can use a combination of the nextFocus*
attributes.
Something like :
<EditText
android:id="@+id/txt1"
android:imeOptions="actionNext"
android:nextFocusForward="@+id/txt3"
android:nextFocusDown="@+id/txt3"
... />
<!-- skipped view -->
<EditText
android:id="@+id/txt2"
android:imeOptions="actionNext"
... />
<EditText
android:id="@+id/txt3"
android:imeOptions="actionNext"
android:nextFocusUp="@id/txt1"
... />
nextFocusForward
is the one used for actionNext
. I believe the other attributes are mostly useful in non touch mode (e.g. with a hardware keyboard)
Upvotes: 0
Reputation: 21381
enabled
property to false
Upvotes: 1