アクションバーにメニュー項目があります。onOptionsItemSelected で、メニュー項目の画像を変更したい。
これが私のコードです
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.todaySched:{
viewTodaySched();
item.setIcon(R.drawable.calendarselected);
infoLog=(MenuItem)findViewById(R.id.infoLog);
infoLog.setIcon(R.drawable.book);
return true;}
case R.id.infoLog:{
viewInfoLog();
item.setIcon(R.drawable.bookselected);
todaySched=(MenuItem)findViewById(R.id.todaySched);
todaySched.setIcon(R.drawable.calenderselected);
return true;}
default:
return super.onOptionsItemSelected(item);
}
}
しかし、アイコンをクリックしてもアイコンが変わらず、実行時エラーが発生しました。例: todaySched アイコンをクリックすると、infoLog アイテム ID を取得できないようです。
マイ LogCat: LogCat