简体   繁体   中英

Switching from portrait to landscape two different view

Im working on application in that I want ListView with images in portrait mode and GalleryView with same images in Landscape mode I created folder in res/layout-land/main.xml(Landscape) and normal res/layout/main.xml (portrait) but I'm getting an exception

03-02 11:21:06.420: E/AndroidRuntime(775): FATAL EXCEPTION: main
03-02 11:21:06.420: E/AndroidRuntime(775): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.landscape/com.landscape.ListAvtivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.os.Looper.loop(Looper.java:130)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-02 11:21:06.420: E/AndroidRuntime(775):  at java.lang.reflect.Method.invokeNative(Native Method)
03-02 11:21:06.420: E/AndroidRuntime(775):  at java.lang.reflect.Method.invoke(Method.java:507)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-02 11:21:06.420: E/AndroidRuntime(775):  at dalvik.system.NativeStart.main(Native Method)
03-02 11:21:06.420: E/AndroidRuntime(775): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ListActivity.onContentChanged(ListActivity.java:243)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.Activity.setContentView(Activity.java:1657)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.landscape.ListAvtivity.onCreate(ListAvtivity.java:43)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-02 11:21:06.420: E/AndroidRuntime(775):  ... 11 more

and when i delete main.xml from layout-land the application works fine and displays only ListView.

Add the main.xml which is in layout-land in your question.

The ListView in the layout-land/main.xml looks to not contain android:id="@android:id/list"

EDIT

The activity should not extend ListActivity but only Activity because it search in the contentview a listview with id @android:id/list .

You have to use the ListView manually.

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