我有一个动作栏上的菜单项。在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