Touchable Touch Focusable Element

I have an editText that I want to fill out automatically with information from other controls on the form and at the same time allow it to change its contents, not encouraging the user from doing this.

So, I set this control to be defocusable, so when you press actionNext, it moves on to the next control. However, if you click on the edit text, I want to allow the user to modify 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 strangely, as a result, when you click, you can edit, but suddenly the next control (AutoCompleteTextView) no longer focuses! Actually, it seems that the main focus remains in the editing text and at the same time goes to the autocompletetextview file, for example:

enter image description here

How can i fix this?

+7
android
source share
2 answers
  • Subclass to view text.
  • Use it in your presentation.
  • Set the enabled property to false
  • Overwrite touch handlers in your subclass: when you touch text editing, turn on viewing and concentrate it. When the focus is lost, turn off the text view again. Do it all in a subclass.
  • Correctly create a text editing view so that the user has the impression that it is being edited
+1
source share

If you want automatic focus changes to skip some views, you can use a combination of 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 that other attributes are mostly useful in non-touch mode (for example, with a hardware keyboard).

0
source share

All Articles