Android One page on multiple listview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.