Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unfocusable element, focusable on touch

Tags:

android

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:

enter image description here

How can I fix this?

like image 356
MichelReap Avatar asked Sep 05 '17 14:09

MichelReap


People also ask

Is focusable in touch mode?

In touch mode, there is no focus and no selection. Any selected item in a list of in a grid becomes unselected as soon as the user enters touch mode. Similarly, any focused widgets become unfocused when the user enters touch mode.

How do you make an element not focusable?

In order to make an prevent an element from taking focus ("non-focusable"), you need to use Javascript to watch for the focus and prevent the default interaction. In order to prevent an element from being tabbed to, use tabindex=-1 attribute. Adding tabindex=-1 will make any element focusable, even div elements.

What is the use of focusable in Android Studio?

Your view can have different background when state is focused. Focusable in touch mode allows view to gain focus when user is touching the view, good example of this kind of component is EditText . With Button or any clickable component pressed state is usually what you are interested in.

How to make an element 'Un-focusable'?

I think you can make an element 'un-focusable' by defocusing it every time it is focused. You can accomplish this via: document.getElementById ("myElement").onfocus = function () { this.blur (); };

How do you make an element focusable in HTML?

Any element with a tabindex. For an otherwise unfocusable element to become focusable, it must have a tabindex attribute. Elements with a negative tabindex can receive focus through scripting but not through keyboard tabbing. A web page’s focus order must preserve a page’s meaning and promote ease of use.

How to make a tab index focusable?

(Just added as an FYI for other googlers.) Note that divs with contenteditable="true" can also receive focus. Show activity on this post. Additionally, If you want to make a focussable element (form input elements etc.) as unfocussable. You can set : tabIndex = "-1" document.getElementById ("yourElement").setAttribute ("tabIndex", "-1");

How do I move the focus of an element?

In most browsers, users can move focus by pressing the Tab key and the Shift + Tab keys. The following elements can receive focus: Any element with a tabindex. For an otherwise unfocusable element to become focusable, it must have a tabindex attribute.


1 Answers

  • Make a sub class of your text edit view
  • Use it in your view
  • Set its enabled property to false
  • Overwrite the touch handlers within your subclass: when the text edit view is touched, enable the view now and focus it. When the focus is lost, disable the text edit view again. Do all that in the subclass.
  • Style the text edit view properly so that the user has the impression that it's editable
like image 117
Lars Blumberg Avatar answered Oct 05 '22 20:10

Lars Blumberg