Android: view id list

I have a list declared in my xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="#F7EFE8"> <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_message"/> </LinearLayout> 

But when I try to declare / use it in java, the identifier is not found. But when I rename the list view to something else and try to use it, I can see it "R.id._", but when R.id.list I can not find it. And if I did not use android: list there an error, which should look like a list whose id is android: list. Any help here?

+8
android listview
source share
3 answers

ListView object id must be specified as android: id = "@android: id / list"

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

or it should have some other identifier, for example android: id = "@ + id / sampleList"

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

Check this out: ListActivity

and list

Hope this helps.

+25
source share

In using 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 list then replace your code as

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

It can help you.

+3
source share

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

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


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

0
source share

All Articles