Put the listview in scroll, and solve the problem that scroll Initialization is not set to the top, listviewscroll
First, if you put listview in scroll, The listview is not displayed completely. In this case, you need to dynamically modify the length of the listview.
Public void setListViewHeight (ListView listView) {// obtain the Adapter ListAdapter listAdapter = ListView corresponding to the listView. getAdapter (); if (listAdapter = null) {return;} int totalHeight = 0; for (int I = 0, len = listAdapter. getCount (); I <len; I ++) {// listAdapter. getCount () returns the number of data items. View listItem = listAdapter. getView (I, null, listView); listItem. measure (0, 0); // calculate the width and height of the subitem View totalHeight + = listItem. getMeasuredHeight (); // calculate the total height of all subitems} ViewGroup. layoutParams params = listView. getLayoutParams (); params. height = totalHeight + (listView. getDividerHeight () * (listAdapter. getCount ()-1); listView. setLayoutParams (params );}
After success, it is found that scroll is not set to the top.
myscroll.smoothScrollTo(0,20);
OK.
ScrollView nested listview for android
The listItem method can only be used to display static data, that is, the data is written to death.
To Display Dynamic Data, you must customize a ListView and write a class to inherit Linearlayout.
Android development problem: scrollView is used for the entire activity. There are two listView in it. How can we solve the sliding conflict between scrollView and ListView?
I have encountered a similar problem. I wrote a popular solution on the Internet as a separate tool class, and then each listview called this tool class after setting the adapter. However, sometimes the last item of the listview is not completely displayed, which is basically a layout problem.