android - Fragment onKeyDown() not working as intended -
i have framgments called in order fragone calls fragtest , fragtest calls fragbook. when current fragment fragbook on pressing button, fragtest shown split second , app sent app tray.
@override public boolean onkeydown(int keycode, keyevent event) { fragmentmanager fragmanager = getsupportfragmentmanager(); fragment frag = fragmanager.findfragmentbytag("frag_book"); if ((keycode == keyevent.keycode_back)) { if (frag.isvisible()) { fragmanager.begintransaction() .replace(r.id.container, fragment.instantiate(mainactivity.this, fragments[1]),"frag_test") .commit(); } } return super.onkeydown(keycode, event); }
where have gone wrong in approach? thanks...
@override public boolean onkeydown(int keycode, keyevent event) { fragmentmanager fragmanager = getsupportfragmentmanager(); fragment frag = fragmanager.findfragmentbytag("frag_book"); if ((keycode == keyevent.keycode_back)) { if (frag.isvisible()) { fragmanager.begintransaction() .replace(r.id.container, fragment.instantiate(mainactivity.this, fragments[1]),"frag_test") .commit(); return true; //"------------- should add" } } return super.onkeydown(keycode, event); }
Comments
Post a Comment