The use of Android development Listview-arrayadapter

Source: Internet
Author: User

Arrayadapter:

Arrayadapter<string> (context context, int resource, int textviewresourceid, string[] objects)

Parameters:

1.context: Context

2.resource: Layout file

3.TEXTVIEWRESOURCEID: Resource ID of the data textview to be displayed

4.objects: The data to be displayed can only be a string

Use of the arrayadapter of the ListView

Code:

1 Importandroid.app.Activity;2 ImportAndroid.os.Bundle;3 ImportAndroid.widget.ArrayAdapter;4 ImportAndroid.widget.ListView;5 6  Public classMainactivityextendsActivity {7     8     PrivateListView LV;9 Ten @Override One     protected voidonCreate (Bundle savedinstancestate) { A         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -          theString[] Objects =Newstring[]{ -"Xiao Zhi", "Xiao Zhi's wife", "Meng Meng", "Xiao Zhi's son" -         }; -          +lv=(ListView) Findviewbyid (r.id.lv); -Lv.setadapter (NewArrayadapter<> ( This, R.layout.item_view, R.id.lv_name, objects)); +     } A  at}

Item_view Layout file:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Wrap_content"5 android:orientation= "Horizontal" >6 7     <ImageView8         Android:id= "@+id/lv_phono"9 Android:layout_width= "60DP"Ten Android:layout_height= "60DP" One android:src= "@drawable/img01" /> A  -     <TextView -         Android:id= "@+id/lv_name" the Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - android:layout_gravity= "Center_vertical" - Android:text= "First Name" + android:textsize= "20SP" /> -  + </LinearLayout>
Activity_main Layout file:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context=". Mainactivity " >6 7     <ListView8         Android:id= "@+id/lv"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Match_parent" > One     </ListView> A  - </Relativelayout>

The use of Android development Listview-arrayadapter

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.