My app uses keyboard control and when moving around I've noticed that occasionally you get what I'll refer to as a "Mystery View" - I say that because nothing visible seems to be selected, yet nothing visible is focussed either
Is there any way to find out what I'm focussed on at any given time? eg. a listener that fires on a view selection, etc.
Thanks
** edit - some code for ntc **
LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
Button btn = new Button(this);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
if(col1.getFocusedChild() != null) {
Log.d(TAG, col1.getFocusedChild().toString());
}
}
});
col1.addChild(btn);
isFocused() method tells whether the view in question is focused or not. Or else, you can compare your views by id. @CGR Well, isFocused() is the preferred way to go here. getCurrentFocus() can return a null view, so you should do a null check first if you decide to use getId().
Click in the rendered webpage to put focus on it, and then press Tab or Shift + Tab to move focus around in the rendered webpage.
Use the blur() method to remove the focus from an element, e.g. input. blur() . If you need to remove the focus from the currently active element without selecting it, call the blur method on the activeElement property - document. activeElement.
getWindow().getCurrentFocus();
You can probably use this method for every view. Maybe this may gets bigger and hectic but is sure to work:
if(yourChildView.isFocused()) {
yourChildView.setFocusable(false);
}
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