I am trying to design simple universal controller in Android. I have created left, right, up, down, pause, resume and selection buttons to perform the selection,navigation and some media control tasks.
When I focus on the pause button with the TAB key on my physical keyboard, I click the selection button I created in my application. Focused pause button not working. But if I press the enter key on my physical keyboard instead of pressing the selection(ENTER) button in my application, the focused pause button works.
In short, the ENTER key event doesn't seem to work the same as the enter key on a physical keyboard in my simple application.
Related code parts,
...
Button rightButton = findViewById(R.id.right_button);
rightButton.setFocusable(true);
rightButton.setFocusableInTouchMode(true);
Button selectButton = findViewById(R.id.select_button);
selectButton.setFocusable(true);
Button pauseButton = findViewById(R.id.pause_button);
pauseButton.setFocusable(true);
pauseButton.setFocusableInTouchMode(true);
...
...
selectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("UNIVERSAL CONTROLLER: ", "ENTER");
keySelection(KeyEvent.KEYCODE_ENTER);
}
});
...
...
public void keySelection(int keyCode)
{
dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
}
...