Reputation: 215
Problems trying to display data from a DB to a listview using a custom cursor adapter. I think I have traced the issue to not being able to 'find' my listview element from the xml file.
In my XML file, I have this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="7" >
<ListView
android:id="@+id/android:list"
android:background="?android:attr/activatedBackgroundIndicator"
android:choiceMode="singleChoice"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I have this in my main onCreate for my activity:
setContentView(R.layout.activity_trip_display);
.... // other code
tripList = (ListView) findViewById(R.id.list);
But that last line produces a 'list cannot be resolved or is not a field' error in Eclipse.
If I add 'android' in there:
tripList = (ListView) findViewById(android.R.id.list);
it compiles OK but then I get a null entry for the variable 'tripList' which causes other NPE errors.
Any ideas?
EDIT: ok, I think my problem is my cursor adapter - will post a new question. Thank you all for looking...
Upvotes: 0
Views: 76
Reputation: 47817
If your ListView
id is android:id=@android:id/list"
then no need to defined
tripList = (ListView) findViewById(android.R.id.list);
and your Activity
must Extends ListActivity
and also no need to add setContentView()
as @AndroidWarrior's comment
and if your ListView
id is android:id="@+id/list"
then initialized your ListView
with
tripList = (ListView) findViewById(R.id.list);
Go to this for more Demos http://www.vogella.com/tutorials/AndroidListView/article.html
Upvotes: 1
Reputation: 398
I think the problem with android:id="@+id/android:list" replace with this
android:id="@+id/list" and extend your application to Activity is enough.
ListView list = (ListView) findViewById(R.id.list);
accept ans if problem solved.
Upvotes: 0
Reputation: 18923
If you want to use this in your coding
tripList = (ListView) findViewById(android.R.id.list);
then your class must be extends with ListActivity
.
and change in your xml for ListView
id like
android:id="@+id/android:list"
to
android:id ="@android:id/list"
Upvotes: 0
Reputation: 627
Instead of android:id="@+id/android:list"
use android:id="@+id/list"
Upvotes: 0