Okay so I have a custom view inside a dialog but its onKeyDown never get called. I tried onKeyPreIme too but didn’t work and setting dialog’s setCancelable to true didn’t help either.
edit :
//Removed all unnecessary code
public class CustomView extends LinearLayout
{
@Override
public boolean onKeyDown (int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
//do stuff here
return true;
}
return super.onKeyDown(keyCode, event);
}
}
public class CustomDialog
{
Dialog dialog;
public class CustomDialog(Context context)
{
dialog = new Dialog(context);
dialog.setContentView(R.layout.test);// the test.xml has CustomView
}
}
Move your
onKeyDownlogics to anOnKeyListenerimplementation and register it in your View’s constructor.