android - webview fragment press back to return to -
hi have android app recycleview
. when user click button
on recycle viewholder
. app launch webview
(inside fragment
). want handle when user click button, webview
goback if there history, , if there no history, app close webview
fragment , come recycleview
.
i have successfull handle when there history (but webview can not come recycle view if there no history
here webview code
webview.setonkeylistener(new view.onkeylistener() { public boolean onkey(view v, int keycode, keyevent event) { if (keycode == keyevent.keycode_back) { if (webview.cangoback()) { webview.goback(); }else { getactivity().getsupportfragmentmanager().popbackstack(); } return true; } return false; } });
anything wrong these code? appreciate. thanks
edit use these code inside recycleview
adapter
class handle button click on viewholder
class
url.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { bundle bundle = new bundle(); bundle.putstring("topstoryurl", topstories.get(getlayoutposition()).geturl()); topstorywebview topstorywebviewfragment = new topstorywebview(); topstorywebviewfragment.setarguments(bundle); if (itemlistactivity.mtwopane) { ((fragmentactivity) context).getsupportfragmentmanager() .begintransaction() .add(r.id.item_detail_container, topstorywebviewfragment) .commit(); } else { topstorywebviewfragment.setarguments(bundle); ((fragmentactivity) context).getsupportfragmentmanager() .begintransaction() .add(r.id.framelayout, topstorywebviewfragment) .commit(); } } });
addtobackstack add fragment stack, , can access stack later
((fragmentactivity) context).getsupportfragmentmanager() .begintransaction() .add(r.id.item_detail_container, topstorywebviewfragment) // add transaction stack (name optional name stack state, or null). .addtobackstack(null) .commit();
Comments
Post a Comment