Having trouble getting an onKeyListener to work. I have created a dynamic gridlayout populated with textviews. The gridlayout supports horizontal and vertically scrolling, no problems. Once gridlayout is created and populated I create a view as shown, set the first cell background to Green, for no better reason than to test. I then have the onKeyListener. I have the Log just to see if anything happens, which it doesn't. As I scroll the grid I get nothing in logcat. Am I totally missing the way to use onKeyListener?
Java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View fc = new View(this);
fc = (View) gridLayoutE.getChildAt(0);
fc.setBackgroundColor(Color.GREEN);
gridLayoutE.requestFocus();
fc.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
Log.d("TEST ", String.valueOf(keyEvent));
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN){
if(i== KeyEvent.KEYCODE_DPAD_RIGHT){
Log.d("TEST ", String.valueOf(keyEvent));
return true;
}
}
return false;
}
});
}