android - Automatically disable/enable a listener based on its Fragment visibility -
in android app, have two fragments:
a fragment listview of items
a fragment imageview
through callback onlistitemselected, when user clicks on listview item, mainactivity pushes imageview on stack , fragment image appears on screen. @ point expect that, since listview fragment no longer visible, events associated fragment no longer fired. not case. if touch imageview, listeners of listview items still fire.
two questions:
is there way automatically enable/disable listeners based on fragment visibility?
if not, guess way go disable listview fragment view , re-enable when backbutton pressed. how can capture backbutton event in mainactivity re-enable disabled view?
public class mainactivity extends fragmentactivity implements listviewfragment.callbacks {
[...]
public void onlistitemselected(string str) { fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.addtobackstack(null); fragmenttransaction.replace(r.id.listview, f); fragmenttransaction.commit(); // disable listview //view lw = getsupportfragmentmanager().findfragmentbyid(r.id.listview).getview().findviewbyid(r.id.my_listview); //lw.setenabled(false); }
you can try 2 things
set imageview consume touch events.
imageview.setclickable(true);
when pushing new fragment disable touch events on listview.
listview.setclickable(false);
if want know how know when fragment imageview removed try settargetfragment. take here: https://stackoverflow.com/a/13733914/935421
Comments
Post a Comment