ListView of UI Controls

Source: Internet
Author: User

One, a simple list of TextView
 Public classFirstactivityextendsActivity {Privatestring[] data = {"Apple", "Banana", "Orange", "Watermelon",            "Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango","Apple", "Banana", "Orange", "Watermelon","Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango"}; @Overrideprotected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (r.layout.first_layout); arrayadapter<string> adapter =NewArrayadapter<string> (//arrayadapter Array AdapterFirstactivity. ThisAndroid. R.layout.simple_list_item_1, data);The first parameter, the context object, the second argument, an official built-in layout ID (this is a texview); The third argument, the incoming dataListView ListView = (ListView) Findviewbyid (R.id.listview);    Listview.setadapter (adapter); }}

Second, how can be fun things only text view (to point Complex) 1. Create a new class for storing fruit
 Public class Fruit {    private String name;    Private int imageId;    //constructor initialization     Public int imageId) {This        . Name = name;        this. imageId = ImageId;    }     Public String GetName () {        return name;    }     Public int Getimageid () {        return imageId;    }}
2. Create a custom layout file

Used to describe the layout, waiting to be called

<LinearLayout xmlns:Android="Http://schemas.android.com/apk/res/android"    Android:Layout_width="Match_parent"    Android:Layout_height="Match_parent"    Android:Orientation="Horizontal">    <ImageView        Android:ID="@+id/fruit_image"        Android:Layout_width="50DP"        Android:Layout_height="50DP" />    <TextView        Android:ID="@+id/fruit_name"        Android:Layout_width="Wrap_content"        Android:Layout_height="Wrap_content" /></LinearLayout>
3. Custom adapter, inherited from Arrayadapter

ListView of UI Controls

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.