简体   繁体   中英

How to start ListActivity from intent?

I have a class ListNotes which extends a ListActivity and in another class I have an intent which reffers to a ListNotes class. The problem is that I get an error "Sorry! The application has stopped unexpectedly. Please try again". When I change a ListActivity to just an Activity , the error disappears. But I really need to extend a ListActivity , as I have a ListView in it. Can I modify this code

Intent intent = new Intent(MyNotepad.this, ListNotes.class);
        startActivity(intent);

to make it work? Maybe there is sth like startListActivity(intent); ?

Make sure that you have added a ListView in the layout:

<ListView android:id="@android:id/list"
          android:layout_width="fill_parent">

The @android:id/list id is important for being able to use a ListActivity.

Do you have ListNotes declared as an activity in your Manifest file?

Put this in between the application tags:

<activity
    android:name="ListNotes" />

Also, an error log from LogCat would help.

Edit: The layout used in your ListNotes activity must contain a ListView with id @android:id/list , like the kgiannakakis mentioned.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM