android - Handle back press on top fragment -
i have 2 fragments [a] , [b].
in fragment [a] , want ignore press have following code
view view = inflater.inflate(r.layout.fragment_confirmation, container, false); view.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { if (keycode == keyevent.keycode_back) { return true; } return false; } });
this works fine on fragment [a]. when add fragment [b] backstack, seems fragment [b] cannot handle press although, logic ignore press in fragment[a] . can explain strange behaviour?
try may works.override key in onresume ...
@override public void onresume() { super.onresume(); getview().setfocusableintouchmode(true); getview().requestfocus(); getview().setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { if (event.getaction() == keyevent.action_up && keycode == keyevent.keycode_back){ // handle button return true; } return false; } }); }
Comments
Post a Comment