Wednesday, March 14, 2012

[android-developers] OnKeyListener is not working, why?

I have a fragment class, in the fragment class, I implement the
onCreateView(...) callback in the following way:

********************************************************************************************************************
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View myView = inflater.inflate(R.layout.note, null);

myView.setOnKeyListener(
new OnKeyListener(){
@Override
public boolean onKey( View v, int keyCode, KeyEvent event ){

if( keyCode == KeyEvent.KEYCODE_BACK ){
Log.v("CALL ME", "I am called");
return true;
}
return false;
}
});

return myView;
}

***************************************************************************************************************
As you see above, I inflate a layout to this fragment, then I
setOnKeyListener() to handle the back button press event. But when I
run it on my phone, the back button press event is not handled, my Log
message is not showing. Why my OnKeyListener is not working ???

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate