I have a menu_item
and here is the code:
<item
android:id="@+id/action_search"
android:actionViewClass="android.widget.TextView"
android:title="In Stocks"
app:showAsAction="always" />
<item
android:id="@+id/action_checkbox"
app:actionViewClass="android.widget.CheckBox"
android:title="@string/action_check"
app:showAsAction="always"
/>
I am trying to catch Menu_item_clicked_event
So, I write following code in Activity
file
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_checkbox:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.action_search:
System.out.println("xas");
default:
return super.onOptionsItemSelected(item);
}
}
When I am pressing the action_search
it's working but not for action_checkbox
. Why this is happening? I am getting No exception in ADB logs
. Is this is the right way to do check for Checkboxes
?