How to realize the nesting of two ListView in ScrollView by Android Development
Most people do not understand the knowledge points of this article "Android Development how to achieve the nesting of two ListView in ScrollView", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Android development how to achieve the nesting of two ListView in ScrollView" article.
The details are as follows:
In the project, you need to use two ListView to display on the same page. Because the data source is different, you can't distinguish the display by setting the flag bit in Adapter. In the end, you can only do a ScrollView to nest two ListView, but under normal circumstances, it cannot be displayed at the same time. The above ListView will be fully displayed, and the lower one only shows an Item. After looking up some information, you have finally succeeded.
There is mainly a ListViewUtility with the following code:
Import java.io.File;import android.content.Intent;import android.net.Uri;import android.view.View;import android.view.ViewGroup;import android.widget.ListAdapter;import android.widget.ListView;public class ListViewUtility {/ / is the display layout public static void setListViewHeightBasedOnChildren (ListView listView) {ListAdapter listAdapter = listView.getAdapter (); if (listAdapter = = null) {/ / pre-condition return;} int totalHeight = 0 added to a Scrollview. For (int I = 0; I < listAdapter.getCount ()) {/ / Global.pos = i; View listItem = listAdapter.getView (I, null, listView); listItem.measure (0,0); totalHeight + = listItem.getMeasuredHeight ();} ViewGroup.LayoutParams params = listView.getLayoutParams (); params.height = totalHeight + (listView.getDividerHeight () * (listAdapter.getCount ()-1)); listView.setLayoutParams (params);}}
Then write two more Listview, as follows
SignListview.setAdapter (mYinggaoSignListAdapter); appListView.setAdapter (adapter); ListViewUtility.setListViewHeightBasedOnChildren (signListview); ListViewUtility.setListViewHeightBasedOnChildren (appListView)
Finally, add two ListView to the ListViewUtility, and the two ListView should be filled and then added. The outermost layer of the layout of the adpter in the two ListView should use LinearLayout. Only the LinearLayout in the ListViewUtility can successfully measure the height of each Item, otherwise there will be an error.
The above is about the content of this article on "how to achieve the nesting of two ListView in Android development ScrollView". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.