Android implementation QQ list type of classification suspension hint _android

Source: Internet
Author: User

Effect Chart:

The implementation of this effect here is a custom ExpandableListView , to give it an indication of the layout, in the sliding process to monitor whether the current should be suspended display classification to achieve. Take the time today, sort out the code, and record the use process so that you can quickly fix it when you have similar requirements.

Without saying much, we look directly at the code and how to use it.

A project structure


The top three classes are our custom ExpandableListView , the main interface, and ExpandableListView the use of Adapter . Below are several XML files are the main interface layout, indicator layout, ExpandableListView child layout, ExpandableListView group layout.

Two implementation code

1. Declare a custom Expandablelistview in XML

<test.com.expandablelistviewdemo.customexpandlistview//Here is not the only, see you specifically put Customexpandlistview where
android:id= " @+id/listview " 
android:layout_width=" match_parent " 
android:layout_height=" match_parent "></" Test.com.expandablelistviewdemo.customexpandlistview>

2. Declare data source related (here for demonstration, the data is all string type, see the specific requirements can be changed)

Private string[] Parentsource = {"Category 1", "Category 2", "Category 3", "Category 4", "Category 5"};
Private arraylist<string> parent = new arraylist<> ();
Private map<string, arraylist<string>> datas = new hashmap<> ();

3. Initialize Demo data

Kind for
(int i = 0; i < parentsource.length i++) { 
parent.add (parentsource[i]);
Add analog data for each type for
(int i = 0; i < parent.size (); i++) { 
String str = parent.get (i); 
arraylist<string> temp = new arraylist<> (); 
for (int j = 0; J < J + +) {  
Temp.add ("" + j); 
} 
Datas.put (str, temp);
}

4. Initialization of adapter and use of

Myadapter = new Myadapter (this, parent, datas, ListView);
Listview.setadapter (Myadapter);

adapterwhen initializing, we can see that we have passed the context object, the kind, the data, and our object in the construction method, CustomExpandListview so CustomExpandListview we want to add the corresponding construction method in the.

5. Set the floating prompt layout

Listview.setheaderview (Getlayoutinflater (). Inflate (R.layout.indictor_layout, ListView, False));

6. Other

All expand by default

for (int i = 0; i < parent.size (); i++) { 
listview.expandgroup (i);
}

Item Click event

Listview.setonchildclicklistener (New Expandablelistview.onchildclicklistener () { 
@Override public 
Boolean Onchildclick (Expandablelistview expandablelistview, view view, int i, int i1, long l) {  
 Toast.maketext ( Mainactivity.this, "Click on the First" + (i + 1) + "class" + I1 + "item", Toast.length_short). Show ();  
 return true; 
 }
}
);

Three summary

From the top of the steps can be seen, the use of customexpandlistview to achieve the effect of the diagram is very easy, the above is the entire content of this article, I hope that the study or work to bring some help, if there are questions can be exchanged message.

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.