开发者

How to start ListActivity from intent?

I have a class Lis开发者_开发百科tNotes 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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜