我正在尝试为 2 个选项卡创建 2 个选项卡和 2 个不同的活动。但在启动活动期间抛出错误。这是我的代码:
public class CashSales extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cash_sales_tab);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
CustomerAddActivity.class, null);
mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
ItemAddActivity.class, null);
}
}
这是我的活动,将出现在一个选项卡中。
public class CustomerAddActivity extends FragmentActivity {
private EditText mName;
private EditText mEmail1;
private Integer mPkid;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_customer_add);
mName = (EditText) findViewById(R.id.customer_add_name);
mEmail1 = (EditText) findViewById(R.id.customer_add_email1);
Button confirmButton = (Button) findViewById(R.id.customer_add_button);
'''''''''''''''''''''''''''
}
}
目录日志:
02-26 05:52:39.732: E/AndroidRuntime(25579): FATAL EXCEPTION: main
02-26 05:52:39.732: E/AndroidRuntime(25579): java.lang.ClassCastException: asia.wavelet.android.customer.CustomerAddActivity cannot be cast to android.support.v4.app.Fragment
02-26 05:52:39.732: E/AndroidRuntime(25579): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
02-26 05:52:39.732: E/AndroidRuntime(25579): at android.support.v4.app.FragmentTabHost.doTabChanged(FragmentTabHost.java:339)
02-26 05:52:39.732: E/AndroidRuntime(25579): at android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:276)