I'm trying to implement a SearchView ActionBar element, as Android developers say, but I'm having problems. ( http://developer.android.com/guide/topics/ui/actionbar.html ).
There are two errors that, although I searched a lot, I could not find a solution.
1) I have a problem with the MenuItemCompat class. It says: The getActionView (MenuItem) method is undefined for the MenuItemCompat type
I can use the following methods only for this class:
- setShowAsAction (item, actionEnum)
- setActionView (element, view)
Here is the code
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.restloader, menu); MenuItem searchItem = menu.findItem(R.id.search_menu); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
2) There is a problem with this: XMLNS: MyApp = "http://schemas.android.com/apk/res-auto" I do not understand why it is used, but if Google talks about it, it should be appropriate.
Error message: Several annotations found on this line: - error: resource identifier found for the attribute "actionViewClass" in the package 'Com.example.pruebahttp3' - error: resource identifier not found for the attribute 'showAsAction' in the package 'Com. example.pruebahttp3 '
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/search_menu" android:orderInCategory="100" android:title="@string/search" android:icon="@drawable/ic_search_category_default" myapp:showAsAction="ifRoom|collapseActionView" myapp:actionViewClass="android.support.v7.widget.SearchView"> </item>
Thank you very much!
source share