0

我有一个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:a 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();    
} 

但随后出现错误,

logcat如下:

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 的新手,但被卡住了。在此先感谢您的帮助!

4

1 回答 1

0

Comment_movie 应该扩展活动:

public class Comment_movie extends Activity {

    // ...class content
}
于 2013-06-09T09:31:28.523 回答