android - Automatically disable/enable a listener based on its Fragment visibility -


in android app, have two fragments:

  1. a fragment listview of items

  2. 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:

  1. is there way automatically enable/disable listeners based on fragment visibility?

  2. 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

  1. set imageview consume touch events.

    imageview.setclickable(true);

  2. 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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -