Put the listview in scroll, and solve the problem that scroll Initialization is not set to the top, listviewscroll

Source: Internet
Author: User

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.
 

Related Article

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.