2012-02-14 28 views
0

私の活動に関するオプションメニューがあります。 、オプションメニューで空白の画面が表示される

@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を正常に動作している:私は、法の下に使用してオプションメニューのクリックで別のアクティビティを表示しています。上記のアクティビティが表示されます。ただし、2番目のメニュー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> 
+0

をあなたの 'SomeOtherActivity'のコードを投稿してください。 'setContentView(R.layout.your_layout)'を呼ぶのを忘れてしまったと思います。 – WarrenFaith

+0

私は "SomeOtherActivity"のsetContentViewを持っています。protected void onCreate(Bundle savedInstanceState){ \t \t super.onCreate(savedInstanceState); \t \t setContentView(R.layout.follow); } – Reena

+0

あなたはレイアウトに何かが表示されていると確信していますか?あなたの質問にxmlを追加してください。コメントではありません。ありがとう。 – WarrenFaith

答えて

0

何も表示されませんので、あなたのレイアウトは、空である - >空白黒いスクリーン。

いくつかのダミーテキストを表示するために、あなたの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> 
+0

ありがとう!今では私のリストに人口が集まらなかった理由を確認するだけです。 – Reena

0

私はこれが解決策であるかどうかわからないんだけど、試してみてください。

@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); 
} 
+0

あなたを取得できませんでした。それは私と同じコードです。 – Reena

+0

いいえ、そうではありません。私はスイッチの外に戻ります。 – ringkjob

+0

試しました。それは動作しません。 – Reena

関連する問題