オプションの「メニュー」画面を作ろうとしています。メニューボタンが押されると、メニューには「オプション」という「ボタン」が表示され、それがクリックされると、関数は optionsButton と呼ばれるボタンをクリックします。そのボタンが押されると、1 つの TableLayout が非表示になり、もう 1 つが表示されるようになります。
レイアウトを非表示にするために必要なコードは次のとおりです。
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);
}
そして、これが私のoptionButtonを処理するXMLです<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>
そして、これが私の「メニューボタン」を処理するコードです
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;
}
問題は、メニュー ボタンをクリックしても何も起こらないことです。この問題に関するヘルプをいただければ幸いです。