Android: id list view

前端 未结 3 2068
闹比i
闹比i 2021-02-09 02:37

I have a list view declared in my xml:




        
相关标签:
3条回答
  • 2021-02-09 03:09

    In xml layout use,

     <ListView
       android:id="@+id/list"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
    
     />
    

    In Java Code:

     ListView listview=(ListView)findViewById(R.id.list);// it takes id of listview from xml
    

    if you need to use android id for listview then replace your code as

    <ListView
     android:id="@+android:id/list"
     android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    

    It may help you..

    0 讨论(0)
  • 2021-02-09 03:10

    Your ListView object id should be specified either as android:id="@android:id/list"

    ListView lv = (ListView) findViewById(android.R.id.list);
    

    or it should have some other id like android:id="@+id/sampleList"

    ListView lv = (ListView) findViewById(R.id.sampleList);
    

    Check this : ListActivity

    and list

    Hope this would help.

    0 讨论(0)
  • 2021-02-09 03:12

    Try this: android:id="@+id/list" Then clean project and rebuild. In java, just call findViewById like this:

       ListView lv = (ListView)findViewById(R.id.list); 
    


    Ref: http://developer.android.com/reference/android/view/View.html

    0 讨论(0)
提交回复
热议问题