android - How/where in the code to detect wether in ListFragment's ListView all items are visible? -


i trying change actionbar's action depending on wether list items visible (there's less items fit screen => show "add item" action | there items invisible => show "search" action)

what method of listfragment should override in order able use getlistview().getlastvisibleposition() , not -1?

this code listfragment, in oncreateoptionsmenu lv.getlastvisibleposition() returns -1.

@override public void oncreateoptionsmenu(menu menu, menuinflater inflater) {     super.oncreateoptionsmenu(menu, inflater);     inflater.inflate(r.menu.list, menu);      final menuitem search = menu.finditem(r.id.menu_item_search);     final menuitem add = menu.finditem(r.id.menu_item_add_item);      final listview lv = getlistview();     if (lv.getfirstvisibleposition() == 0 && lv.getlastvisibleposition() == madapter.getcount()-1) {         // items visible: show add, hide search         search.setshowasaction(menuitem.show_as_action_never);     } else {         // not items visible: show search, hide add         add.setshowasaction(menuitem.show_as_action_if_room);     }     // ... } 

getlastvisibleposition returns valid position when adapter's items added , layed out hosing listview, don't know method of asking listview when happens, best option listen when ui thread goes block waiting more messages:

looper.myqueue().addidlehandler

and call getlastvisibleposition() inside idlehandler#queueidle()


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -