2011-06-25 8 views
0

私はオプションの「メニュー」画面を作成しようとしています。メニューボタンが押されると、メニューはクリックされたときに「オプション」と表示される「ボタン」を表示し、optionsButtonというボタンをクリックします。そのボタンを押すと、1つのTableLayoutが不可視になり、1つが可視になります。TableLayouts経由で複数の「画面」を処理する

ここではレイアウトを非表示にするコードを示します。

public void optionButton(View view) 
{ 
    TableLayout mainTable = (TableLayout)findViewById(R.id.tableMain); 
    TableLayout optionTable = (TableLayout)findViewById(R.id.tableOptions); 
    mainTable.setVisibility(TableLayout.INVISIBLE); 
    optionTable.setVisibility(TableLayout.VISIBLE); 

} 

そしてここ<Button android:onClick="optionButton" android:id="@+id/optionsButton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:visibility="invisible"></Button>

を私のオプションボタンを処理し、ここで私の「メニューボタン」を処理するコードであるXMLである

public boolean onOptionsItemSelected(MenuItem item) { 
    switch(item.getItemId()) { 
    case R.id.options: 
     Button optbtn = (Button)findViewById(R.id.optionsButton); 
     optbtn.performClick(); 
     break; 
    default: 

     break; 
    } 

    return true; 
} 

問題は、メニューボタンがクリックされたときにということです、 何も起こりません。この問題に関する助けをいただければ幸いです。

+0

あなたのコードが関数onOptionsItemSelected(..)の最初のケースに入るかどうかをデバッグして調べることができますか?R.id.options&itemの値も表示します。その場合、その関数にgetItemId()が含まれていなければ – mkso

答えて

0

optionsTableとそのすべての内容を削除することで問題を解決しました。それを作り直してmain.xmlのグラフィカルエディタのmainTableの下に置く

関連する問題