我創建了自己的導航抽屜活動。一切工作正常,但我想擴展到其他活動。 https://github.com/lupajz/bc/blob/master/app/src/com/kulturnepodujatia/DashboardActivity.java這裏是我的導航抽屜活動。擴展導航抽屜活動
如果我嘗試打開另一個類似的活動,例如:
public class Test extends DashboardActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test, menu);
return true;
}
}
我得到的錯誤:
03-26 12:14:07.902: E/AndroidRuntime(19266): FATAL EXCEPTION: main
03-26 12:14:07.902: E/AndroidRuntime(19266): Process: com.kulturnepodujatia, PID: 19266
03-26 12:14:07.902: E/AndroidRuntime(19266): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kulturnepodujatia/com.kulturnepodujatia.Test}: java.lang.IllegalArgumentException: No view found for id 0x7f07000b (com.kulturnepodujatia:id/frame_container) for fragment BaseFragment{64ababa0 #0 id=0x7f07000b}
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.ActivityThread.access$800(ActivityThread.java:145)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.os.Handler.dispatchMessage(Handler.java:102)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.os.Looper.loop(Looper.java:136)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.ActivityThread.main(ActivityThread.java:5081)
03-26 12:14:07.902: E/AndroidRuntime(19266): at java.lang.reflect.Method.invoke(Native Method)
03-26 12:14:07.902: E/AndroidRuntime(19266): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-26 12:14:07.902: E/AndroidRuntime(19266): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
03-26 12:14:07.902: E/AndroidRuntime(19266): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f07000b (com.kulturnepodujatia:id/frame_container) for fragment BaseFragment{64ababa0 #0 id=0x7f07000b}
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:882)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.BackStackRecord.run(BackStackRecord.java:684)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.Activity.performStart(Activity.java:5240)
03-26 12:14:07.902: E/AndroidRuntime(19266): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178)
測試acitivty剛剛在佈局的textivew。導航抽屜活動有這樣的佈局:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@android:style/Theme.Holo.Light">
<!-- Framelayout pre zobrazovanie jednotlivých fragmentov -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview ako menu pre navDrawer -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:dividerHeight="0dp"
android:divider="@null"
android:background="#2B2B2B"
/>
</android.support.v4.widget.DrawerLayout>
按照該教程http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ –