0

I trying to apply accessibility about talkback on my app.

I want to change the focus to a ImageButton (custom keypad layout) when the user selects EditText.

here is my code summary.

edittext.setAccessibilityDelegate(new View.AccessibilityDelegate() {
    @Override
    public void sendAccessibilityEvent(View host, int eventType) {
        if (eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED || eventType == AccessibilityEvent.TYPE_VIEW_CLICKED) {
            btn.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
        }
    }   
});

I set condition about TYPE_VIEW_CLICKED and TYPE_VIEW_FOCUSED because when user double tap on the EditText, a state can be already focused.

but, if eventType is TYPE_VIEW_CLICKED, the button not only accessibility focus but also cause button click event.

I want to set just focus.

How can I solve this problem?

1 Answers1

0

Option 1 Under onCreate()

editText.requestFocus();

Option 2 - extension of option 1

if(editText.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

Option 3 - if both option 1 & 2 not working

editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
PartTimeNerd
  • 305
  • 1
  • 2
  • 20
  • I don't need to use requestFocus(). EditText's focus will get from the user's double tap gesture. I just want to change accessibility focus to button without button click event. – Jin Eun. Jeong Nov 02 '18 at 06:22
  • I solved this problem using code trick. If `EditText` received `TYPE_VIEW_CLICKED` event, resend `TYPE_VIEW_FOCUSED`. `sendAccessibilittyEvent()` method will be called recursively. Then send event to `ImageButton`. I don't know why dose `ImageButton` work `CLICK`. – Jin Eun. Jeong Nov 04 '18 at 12:33
  • @JinEun.Jeong could you share your code solution with me? Maybe just a snippet from your project through email – PartTimeNerd Nov 05 '18 at 04:31
  • Sorry. I was mistaken about this problem. There is a problem still. but I found a reason why button was clicked. First, It is a device problem on Galaxy Note 4 (Android 6.0). Second, when you touch to click, `onClick` event occur before `ACTION_UP` of touch event. so i processed `if (eventType == `TYPE_VIEW_CLICKED` ...)`. UI focus moved already. so `Button` receive the event of touch `DOWN`, `UP`. – Jin Eun. Jeong Nov 09 '18 at 09:14