Listactivity Point of attention

Source: Internet
Author: User

Sometimes we need to integrate listactivity, Note point 1, this time in our XML <ListView> tags in the id attribute can not be arbitrarily named, but to be fixed to android:id= "@id/ Android:list ", specifically as follows:

Main3.xml:

  

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Fill_parent"4 Android:layout_height= "Fill_parent"5 android:orientation= "vertical" >6 7     <ListView8         Android:id= "@id/android:list"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Wrap_content" /> One  A </LinearLayout>

When we want to get this ListView in activity, note that point 2 can be directly via (ListView) Findviewbyid (Android. R.id.list); the way to get, which is also fixed .

Specific as follows:

Listviewdemo.java:

1  Packagetjuci.edu.dl;2 3 Importandroid.app.Activity;4 Importandroid.app.ListActivity;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.View;7 ImportAndroid.widget.ArrayAdapter;8 ImportAndroid.widget.ListView;9 Ten  Public classListviewdemoextendslistactivity { Onestring[] str = {"Wyl", "Zhangyalan", "Huarong" }; A ListView LV; - @Override -     protected voidonCreate (Bundle savedinstancestate) { the         //TODO auto-generated Method Stub -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.main3); -Arrayadapter<string> A =NewArrayadapter<string> ( This, + Android. R.layout.simple_list_item_1, str); -LV =(ListView) Findviewbyid (Android. r.id.list); + Lv.setadapter (a); A     } at @Override -     protected voidOnlistitemclick (ListView L, View V,intPositionLongID) { -         //TODO auto-generated Method Stub -         Super. Onlistitemclick (l, V, position, id); -String selected =l.getitematposition (position). toString (); -System.out.println ("Checkeditem:" +selected+ ", Position:" +position); in     } -      to      +}

Listactivity Point of attention

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.