我有一个MainActivity.java
,其中TabHost
声明如下:
Intent intent_comment = new Intent(this,Comments.class);
createTab("Comments",intent_comment);
private void createTab(String text ,Intent intent)
{ tabHost.addTab(tabHost.newTabSpec(text).setIndicator(createTabView(text)).setContent(intent));
}
然后在这个Comments.class
内,页面上只有4个按钮,按下按钮后,我想显示Comment_movie.class
:scrollview
(只是像一个网页,里面有按钮,这样当按下按钮时,它会调用其他活动。
因此,我所做的只是在Comments.class
public void button_story_movie_click (View view)
{
Intent intent = new Intent (Comments.this, Comment_movie.class);
startActivity(intent);
Comments.this.finish();
}
但后来出现错误,
06-09 13:02:27.185: E/AndroidRuntime(24252): FATAL EXCEPTION: main
06-09 13:02:27.185: E/AndroidRuntime(24252): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.abc.abc/com.abc.abc.Comment_movie}: java.lang.ClassCastException: com.abc.abc.Comment_movie cannot be cast to android.app.Activity
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.os.Looper.loop(Looper.java:137)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.ActivityThread.main(ActivityThread.java:4921)
06-09 13:02:27.185: E/AndroidRuntime(24252): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 13:02:27.185: E/AndroidRuntime(24252): at java.lang.reflect.Method.invoke(Method.java:511)
06-09 13:02:27.185: E/AndroidRuntime(24252): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
06-09 13:02:27.185: E/AndroidRuntime(24252): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
06-09 13:02:27.185: E/AndroidRuntime(24252): at dalvik.system.NativeStart.main(Native Method)
06-09 13:02:27.185: E/AndroidRuntime(24252): Caused by: java.lang.ClassCastException: com.abc.abc.Comment_movie cannot be cast to android.app.Activity
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
06-09 13:02:27.185: E/AndroidRuntime(24252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
06-09 13:02:27.185: E/AndroidRuntime(24252): ... 11 more
我如何在TabHost
内调用另一个活动?
是否可以通过替换原始Comments
布局(它是所谓的片段?)来显示目标活动,仍然显示屏幕顶部的选项卡?
非常感谢!!我是新手使用TabHost但卡住了。在此先感谢您的帮助!
答案 0 :(得分:0)
Comment_movie应该扩展活动:
public class Comment_movie extends Activity {
// ...class content
}