Nested listview in ScrollView, scrollviewlistview

Source: Internet
Author: User

Nested listview in ScrollView, scrollviewlistview

Although there are many implementation methods on the internet, I still want to share with you that I have forgotten. when implementing this method, I use linearlayout to replace listview.

To put it bluntly, go to the Code:

ExpandListView. java:

Public class ExpandListView extends LinearLayout implements OnClickListener {private ListAdapter adapter = null; private OnItemClickListener listener = null; private Drawable dividerDrawable = null; private int dividerHeight = 0; public ExpandListView (Context context Context) {super (context); // TODO Auto-generated constructor stubinitView (null);} public ExpandListView (Context context, AttributeSet attrs) {super (Context, attrs); // TODO Auto-generated constructor stubinitView (attrs);} public void initView (AttributeSet attrs) {setOrientation (VERTICAL); if (attrs! = Null) {TypedArray array = getContext (). obtainStyledAttributes (attrs, R. styleable. expandListView); dividerDrawable = array. getDrawable (R. styleable. expandListView_divider_view); dividerHeight = array. getDimensionPixelSize (R. styleable. expandListView_divider_height, 0); array. recycle () ;}/ *** bind data */public void bindData () {if (adapter = null) {Logger. e ("adapter is null"); return;} View convertView = nul L; LayoutParams params = null; for (int I = 0; I <adapter. getCount (); I ++) {// if this (parent) is not passed here, when the adapter is in inflate, the parent is null, in this way, the LayoutParams of convertView is empty (the parent control is required for measurement) convertView = adapter. getView (I, null, this); if (convertView. getLayoutParams () = null) {params = new LayoutParams (LayoutParams. MATCH_PARENT, LayoutParams. WRAP_CONTENT);} else {params = (LayoutParams) convertView. getLayoutParams ();} ConvertView. setLayoutParams (params); convertView. setId (I); addDivider (I); if (listener! = Null) {convertView. setOnClickListener (this) ;}addview (convertView) ;}@ SuppressWarnings ("deprecation") public void addDivider (int position) {if (dividerDrawable! = Null | dividerHeight! = 0) & position! = 0) {// Add dividerImageView iv = new ImageView (getContext (); LayoutParams params = null; if (dividerHeight! = 0) {params = new LayoutParams (LayoutParams. MATCH_PARENT, dividerHeight);} else {params = new LayoutParams (LayoutParams. MATCH_PARENT, LayoutParams. WRAP_CONTENT);} iv. setLayoutParams (params); iv. setBackgroundDrawable (dividerDrawable); addView (iv) ;}/ *** set adapter * @ param adapter */public void setAdapter (ListAdapter adapter) {this. adapter = adapter; if (getChildCount ()! = 0) {removeAllViews () ;}binddata () ;}@ Overridepublic void onClick (View v) {// TODO Auto-generated method stublistener. onItemClick (v, v. getId (), adapter);} public void setOnItemClickListener (OnItemClickListener listener) {this. listener = listener;} public interface OnItemClickListener {public void onItemClick (View convertView, int position, ListAdapter adapter );}}

Attrs. xml

<?xml version="1.0" encoding="utf-8"?><resources>    <declare-styleable name="ExpandListView">        <attr name="divider_view" format="reference" />        <attr name="divider_height" format="dimension" />    </declare-styleable></resources>
Easy to use:

 <com.ydk.mikeadmin.view.ExpandListView        android:id="@+id/part_one_list"        android:layout_width="match_parent"        android:layout_height="wrap_content"        mike:divider_height="2dip" />

Then you can directly set the adapter with ExpandListView. setAdapter in the code.

Yes, that's all... the convertView is not reused, so there is no way to reuse it.



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.

Nested Listview in Android ScrollView, a large amount of Listview data

There is a problem with the design. android cannot slide on both sides. Second, is it because the data you load has images ?? If yes, it can be asynchronously loaded. The most common method is to load the first 20 data records by page.

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.