2014-03-26 203 views
0

我創建了自己的導航抽屜活動。一切工作正常,但我想擴展到其他活動。 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> 
+0

按照該教程http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ –

回答

0

就不得不提到這樣

public class Test extends DashboardActivity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

} 

@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 super.onCreateOptionMenu(Menu menu); 
} 
} 

如果你給onCreateOptionsMenu(菜單菜單)上的儀表盤。你永遠不必提過 這裏... 。

繼一個U已經透露了一些內幕清單..

<activity 
       android:name=".Test" 
       android:configChanges="keyboardHidden|screenSize|orientation" 
       > 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
      </activity> 
0

刪除測試活動中的setContentView。您已經在具有R.id.frame_container的Drawer Activity中設置了contentview。所以當你重寫onCreate時,你將使用不同的佈局設置內容視圖,當選擇Drawer itemb時,它會失敗,因爲你試圖在R.id.frame_container中添加片段。

+0

好吧:)這是有益的,現在我有問題。我可以在測試活動中修改此佈局嗎?像刪除切換,只需在那裏放回按鈕? –

+0

當然你可以修改。如果您不覆蓋新視圖,則您可以完全控制該視圖。 – Libin

+0

好吧,我明白了。我的問題是如何訪問另一個活動的第一個活動的ActionBarDrawerToggle? –