[英]Blank screen displayed on option menu click
我的活动上有选项菜单。 我使用以下方法单击选项菜单时显示了另一个活动:
@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
,它将显示黑屏。 不知道发生了什么。
用于SomeOtherActivity的XML:
<?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>
我不确定这是否是解决方案,但是请尝试:
@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;
}
return super.onOptionsItemSelected(item);
}
您的布局为空,因此您将看不到任何内容->黑屏。
将text属性添加到您的TextView中以显示一些虚拟文本:
<?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"
android:text="DUMMYTEXT"
/>
<ListView
android:id="@+id/follow_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.