I'm Implementing Action Bar in my App. But I have problem in switch item action_search, it's like not work. This my menu XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://ift.tt/nIICcg"
xmlns:myapp="http://ift.tt/GEGVYd">
<item
android:id="@+id/action_search"
android:title="@string/menuitem_search"
android:icon="@drawable/ic_action_search"
myapp:actionViewClass="android.support.v7.widget.SearchView"
myapp:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
myapp:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
and this my code
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_search:
Toast.makeText(this, "test search choice", Toast.LENGTH_LONG).show();
return true;
case R.id.action_settings:
Toast.makeText(this, "test setting choice", Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
code above, if I choice action_settings CAN toast test setting choice , but if I choice action_search CAN NOT toast test search choice . how to fix it ?
No comments:
Post a Comment