In android development, different listview are linked at the same time. androidlistview

Source: Internet
Author: User

In android development, different listview are linked at the same time. androidlistview

When creating an Android program, you need to display two different listview items on one screen and start to use <linearlayout> to wrap the two listview items during <ScrollView> setting,

There is a problem that cannot be linked at the same time.

One of the listview is that I need to bind data to this image,

 

 

 

Ignore binding content !!!

Later, we realized that we needed to set the height of each listview and bind it to the View to achieve simultaneous interaction.

1 public void SetListViewHeight (ListView listView) {2 ListAdapter List_Adapter = listView. getAdapter (); 3 if (List_Adapter = null) {4 return; 5} 6 int ALLHeight = 0; 7 for (int I = 0; I <List_Adapter.getCount (); I ++) {8 View listItem = List_Adapter.getView (I, null, listView); 9 listItem. measure (0, 0); // you cannot obtain the View width before creating a View. Before that, we must select measure. 10 ALLHeight + = listItem. getMeasuredHeight (); 11} 12 ViewGroup. layoutParams params = listView. getLayoutParams (); 13 params. height = ALLHeight + (listView. getDividerHeight () * (List_Adapter.getCount ()-1); // listView. getDividerHeight () is used to obtain the height occupied by separators between subitems: 14 15 // params. height: the height of the entire ListView is 16 listView. setLayoutParams (params); 17}

Call the "SetListViewHeight (listview ListView)" function next to the listView to realize simultaneous interaction between two or more different listview views.

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.