Android multiple ListView on a page, when scrolling, requires two ListView to be able to scroll together and look like a view.
The specific implementation of this feature, refer to:
http://blog.csdn.net/xia296/article/details/8128674
The main code is:
/** * Set the listview height, note that the ListView subkey must be linearlayout to call the method * @param listview ListView * */public static void Setlistviewheight (ListView listview) { int totalheight = 0; ListAdapter adapter= listview.getadapter (); if (null! = adapter) {for (int i = 0; I <adapter.getcount (); i++) { View ListItem = Adapter.getview (i, NULL, LIS Tview); if (null! = ListItem) { listitem.measure (0, 0);//Note The ListView subkey must be linearlayout to call the method Totalheight + = Listitem.getmeasuredheight (); } } Viewgroup.layoutparams params = Listview.getlayoutparams (); Params.height = Totalheight + (listview.getdividerheight () * (Listview.getcount ()-1)); Listview.setlayoutparams (params); } }
Use this method specifically in your code:
public void Loadadvancegameview () { if (Madvanceadapter = = null) { madvanceadapter = new Gamedetailadapter ( Mcontext, madvancegamelist); Advancelistview.setadapter (Madvanceadapter); } else { madvanceadapter.notifydatasetchanged (); } Setlistviewheight (Advancelistview); Loadmylocalview (); } private void Loadmylocalview () { mlocalgamelist.clear (); Mlocalgamelist.addall (Appmanager.get (). Getselectedappbeans ()); Removerepeatapp (); if (Mlocaladapter = = null) { mlocaladapter = new Appbeanadapter (Mcontext, mlocalgamelist); Locallistview.setadapter (Mlocaladapter); } else { mlocaladapter.notifydatasetchanged (); } Setlistviewheight (Locallistview); }
When I use it, the view of the item inside the ListView is created with Relativelayout.
But at the back of the test, some machines reported errors.
Specific solutions refer to:
Analysis Java.lang.NullPointerException thrown in relativelayout measure ()
If you start with LinearLayout, you won't get an error.
Android One page on multiple listview