I have option menu on my activity. I am displaying another activity on click of options menu using below method:
@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);
}
}
First menu, some_menu
, is working fine. It displays mentioned Activity. However, when I click second menu, someother_menu
, it displays blank black screen. No idea what is happening.
XML for 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>
I'm not sure if this is the solution, but try:
@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);
}
Your layout is empty, so you will not see anything -> blank black screen.
Add the text attribute to your TextView to show some dummy text:
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.