Parameters for Android Simpleadapter

Source: Internet
Author: User

1. The function is the bridge of the ArrayList and the ListView. each of the ArrayList inside is a map<string,?> type.
Each map object in the ArrayList corresponds to data binding one by one for each item inside the listview.

Constructor for 2.SimpleAdapter:

Simpleadapter (context context, list<? extends Map<string,?>> data, int resource, string[] from, int[] to)

Parameters:
1.context: Context.
2.data: Map-based list. Each item in data corresponds to each item inside the listview. Each item in data is a map type that contains the data needed for each row in the ListView.
3.resource: is a layout, can be referenced by the system provided, or can be customized.
4.from: This is an array of names, each name is used in order to index the Object of each item in the ArrayList array map<string,object>. Which is the key value in the map.
5.to: Inside is a textview array. These textview are represented in the form of an ID. For example: Android.r.id.text1, this text1 can be indexed in layout.

3. Through a subclass to understand the following:

Listitem.xml file:

<?xml version= "1.0″encoding=" utf-8″?> <linearlayout    xmlns:android= "http://  schemas.android.com/apk/res/android"    android:orientation=" Horizontal "android:layout_width= "Fill_parent"    android:layout_height= "Wrap_content" >    <textview android:id= "@+id/  TextView01″android:layout_width="100px"    android:layout_height= "Wrap_content"/>    <textview android:id= "@+id/TextView02″    android:layout_width=" Wrap_content "    android:layout_height= "Wrap_content"/>    </LinearLayout>

Here is some code for the activity file

list<map<string, object>> data =NewArraylist<map<string,object>>(); Map<String,Object>item; Item=NewHashmap<string,object>();    Item.put ("name", "Zhang San");    Item.put ("Gender", "male");    Data.add (item); Item=NewHashmap<string,object>();    Item.put ("name", "John Doe");    Item.put ("Gender", "female");    Data.add (item); //above is the Construction data section. ListView listview=NewListView ( This); //constructs a ListView object. Simpleadapter adapter =NewSimpleadapter ( This, Data,r.layout.listitem,Newstring[]{"Name", "Gender"},New int[]{r.id.textview01,r.id.textview02}]; /*constructs an adapter.    * 1, the third parameter is a description using the custom layout r.layout.listtiem.    * 2, the fourth and fifth parameters are understood together: * When we add data to the name that column corresponds to r.id.textview01 this textview, the gender corresponds to r.id.textview02 this textview.    * If the from is changed to new string[]{"name", "name"}, the test will understand. */Listview.setadapter (adapter); Setcontentview (listview);

Parameters for Android Simpleadapter

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.