如何在功能区菜单android上启动活动

时间:2013-12-06 07:37:03

标签: android menu ribbon

我使用this project作为参考。

当我点击功能区菜单项目时,会显示吐司。 如何在此开始活动或如何动态设置内容并相应地显示(如在Facebook中)。

public void onSlideMenuItemClick(int itemId) {
    switch(itemId) {
    case R.id.item_one:
        Toast.makeText(this, "Item one selected", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, newjava.class)); //this generate error and forcing the app to close.
        break;
}
单击项目

后立即 LogCat
12-06 02:41:32.857: D/AndroidRuntime(2967): Shutting down VM
12-06 02:41:32.857: W/dalvikvm(2967): threadid=1: thread exiting with uncaught exception (group=0xb3a2ab90)
12-06 02:41:32.867: E/AndroidRuntime(2967): FATAL EXCEPTION: main
12-06 02:41:32.867: E/AndroidRuntime(2967): Process: com.coboltforge.slidemenuexample, PID: 2967
12-06 02:41:32.867: E/AndroidRuntime(2967): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.coboltforge.slidemenuexample/com.coboltforge.slidemenuexample.newjava}; have you declared this activity in your AndroidManifest.xml?
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.Activity.startActivityForResult(Activity.java:3423)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.Activity.startActivityForResult(Activity.java:3384)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.Activity.startActivity(Activity.java:3626)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.Activity.startActivity(Activity.java:3594)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at com.coboltforge.slidemenuexample.MainActivity.onSlideMenuItemClick(MainActivity.java:75)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at com.coboltforge.slidemenu.SlideMenu$1.onItemClick(SlideMenu.java:367)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.widget.AdapterView.performItemClick(AdapterView.java:299)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.widget.AbsListView$3.run(AbsListView.java:3638)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.os.Handler.handleCallback(Handler.java:733)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.os.Handler.dispatchMessage(Handler.java:95)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.os.Looper.loop(Looper.java:137)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at android.app.ActivityThread.main(ActivityThread.java:4998)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at java.lang.reflect.Method.invokeNative(Native Method)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at java.lang.reflect.Method.invoke(Method.java:515)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-06 02:41:32.867: E/AndroidRuntime(2967):     at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:1)

使用您的不同活动名称将其添加到清单文件中:因为发生了活动问题的名称...

<activity
    android:name="com.coboltforge.slidemenuexample.yourActivityname" >
</activity>

答案 1 :(得分:0)

您忘了提及清单文件中的活动...将其添加到您的清单文件

<activity
        android:name="com.coboltforge.slidemenuexample.newjava" >
</activity>