onTrackballEvent not firing on Samsung Moment
I have a list in my app.
When a user touches a list item with their finger, the onListItemClick handler fires and I have it opening a new Activity.
However, when a user uses the trackball/pad to click, I want to perform some different functionality. I've overrode onTrackballEvent and everything works perfectly fine in the emulator's trackball mode.
Unfortunately, when testing on the Samsung Moment, clicking the trackpad fires the onListItemClick handler, not the onTrackb开发者_StackOverflowallEvent handler.
Does anyone know why? Does anyone have a way around this?
In listview you can setOnKeyListener and do you code when keycode is KeyEvent.KEYCODE_DPAD_CENTER
listview.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch(keyCode){
case KeyEvent.KEYCODE_DPAD_CENTER:
if(event.getAction()==KeyEvent.ACTION_UP){ //to do it only when key is released
// do the code while trackball/pad is clicked
}
return true;
default:
return false;
}
}
}
});
It work for me. Hope this will give you some idea
Try overriding the dispatchTrackball
event and grab those events. Also, just a suggestion - I would not use a different action on the trackball because not all Android phones have the trackball.
精彩评论