我对我的活动有选项菜单。我使用下面的方法选项菜单中点击显示另一个活动:选项菜单上显示的空白屏幕点击
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent();
switch (item.getItemId()) {
case R.id.some_menu:
intent.setComponent(new ComponentName(MyActivity.this,SomeActivity.class));
startActivity(intent);
return true;
case R.id.someother_menu:
intent.setComponent(new ComponentName(MyActivity.this, SomeOtherActivity.class));
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
一级菜单,some_menu
,工作正常。它显示提到的活动。但是,当我点击第二个菜单someother_menu
时,它会显示空白的黑屏。不知道发生了什么。
XML为SomeOtherActivity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/follow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
/>
<ListView
android:id="@+id/follow_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
请发表您的'SomeOtherActivity'的代码。我想你忘记了调用'setContentView(R.layout.your_layout)'。 – WarrenFaith 2012-02-14 17:44:31
我的setContentView在保护无效的onCreate(捆绑savedInstanceState){ \t \t super.onCreate(savedInstanceState)我的 “SomeOtherActivity”; \t \t setContentView(R.layout.follow); } – Reena 2012-02-14 17:57:09
你确定布局确实显示了一些东西?请将xml添加到您的问题中,而不是作为评论。谢谢。 – WarrenFaith 2012-02-14 18:02:07