找不到类的android.support.v7.widget.SearchView $ 5' [英] Could not find class 'android.support.v7.widget.SearchView$5'
问题描述
我得到y中logcat中此错误。 没有人知道它是什么?
08-22 19:02:57.830:E / dalvikvm(660):找不到类的android.support.v7.widget.SearchView $ 5',从法的Android引用。 support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11
没有很多code熄灭了这里,但我遇到了这个情况我自己,这里就是发生在我身上:
我用的是V7 COMPAT库,以便有一个动作条在Android 2 我实现了搜索界面的东西。
基本设置code(在 onCreateOptionsMenu()
)
SearchManager searchManager =
(SearchManager)getActivity()getSystemService(Context.SEARCH_SERVICE)。
SupportMenuItem searchMenuItem =((SupportMenuItem)menu.findItem(R.id.menu_search));
搜索查看搜索查看=(搜索查看)searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
为code
searchMenuItem.setOnActionExpandListener(新MenuItem.OnActionExpandListener(){
@覆盖
公共布尔onMenuItemActionExpand(菜单项项){
//在搜索扩展的东西
返回true;
}
@覆盖
公共布尔onMenuItemActionCollapse(菜单项项){
//对搜索崩溃的东西
返回true;
}
});
不幸的是这里的问题是,我们调用了仅支持V14这样我们就得到一个怪异的运行时错误时,它会尝试加载一些类,隐式使用的方法。这不是一个很好的解释,但基本上这是我们需要使用同样的道理 getSupportActionBar()
而不是 getActionBar()
。
好code
searchMenuItem.setSupportOnActionExpandListener(新MenuItemCompat.OnActionExpandListener(){
@覆盖
公共布尔onMenuItemActionExpand(菜单项项){
// 做工作
返回true;
}
@覆盖
公共布尔onMenuItemActionCollapse(菜单项项){
// 做工作
返回true;
}
});
I get this error in y Logcat. Does anyone know what it is?
08-22 19:02:57.830: E/dalvikvm(660): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11
There isn't a lot of code to go off of here, but I ran into this situation myself and here is what happened to me:
I was using the v7 compat library in order to have an ActionBar on Android 2 I am implementing the search interface stuff.
Basic Setup Code (in onCreateOptionsMenu()
)
SearchManager searchManager =
(SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
SupportMenuItem searchMenuItem = ((SupportMenuItem) menu.findItem(R.id.menu_search));
SearchView searchView = (SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
Bad Code
searchMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// on search expand stuff
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// on search collapse stuff
return true;
}
});
Unfortunately the problem here is that we are calling a method that is only supported in v14 so we get a "weird" run-time error when it tries to load some classes that are implicitly used. That's not a very good explanation, but basically it's the same reason we need to use getSupportActionBar()
instead of getActionBar()
.
Good Code
searchMenuItem.setSupportOnActionExpandListener(new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// do work
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// do work
return true;
}
});
这篇关于找不到类的android.support.v7.widget.SearchView $ 5'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!