[英]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.