在Sherlock Fragment中,android搜索小部件无法扩展

时间:2013-06-23 05:12:44

标签: android actionbarsherlock

提示:它以前和我合作但我不知道发生了什么 简单地说,当我点击搜索图标时,它不会展开 并在logcat上给我这个,这不是一个例外

06-23 06:51:40.316: D/SherlockFragmentActivity(2027): [onMenuItemSelected] featureId: 0, item: Search
06-23 06:51:40.316: D/ActionBarSherlock(2027): [dispatchOptionsItemSelected] item: Search
06-23 06:51:40.316: D/ActionBarSherlock(2027): [callbackOptionsItemSelected] item: Search
06-23 06:51:40.316: D/Watson(2027): [onMenuItemSelected] featureId: 0, item: com.actionbarsherlock.internal.view.menu.MenuItemWrapper@4187d4b0
06-23 06:51:40.316: D/SherlockFragmentActivity(2027): [supportInvalidateOptionsMenu]
06-23 06:51:40.316: D/SherlockFragmentActivity(2027): [invalidateOptionsMenu]
06-23 06:51:40.316: D/ActionBarSherlock(2027): [dispatchInvalidateOptionsMenu]
06-23 06:51:40.438: D/SherlockFragmentActivity(2027): [onCreatePanelMenu] featureId: 0, menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:40.438: D/ActionBarSherlock(2027): [dispatchCreateOptionsMenu] menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:40.450: D/ActionBarSherlock(2027): [callbackCreateOptionsMenu] menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:40.450: D/Watson(2027): [onCreatePanelMenu] featureId: 0, menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:40.450: D/SherlockFragmentActivity(2027): [getSupportMenuInflater]
06-23 06:51:40.467: D/ActionBarSherlock(2027): [getMenuInflater]
06-23 06:51:40.766: D/Watson(2027): [onCreatePanelMenu] activity create result: true
06-23 06:51:40.766: D/SherlockFragmentActivity(2027): [getSupportMenuInflater]
06-23 06:51:40.766: D/ActionBarSherlock(2027): [getMenuInflater]
06-23 06:51:40.776: D/Watson(2027): [onCreatePanelMenu] fragments create result: false
06-23 06:51:40.776: D/Watson(2027): [onCreatePanelMenu] returning true
06-23 06:51:40.776: D/ActionBarSherlock(2027): [callbackCreateOptionsMenu] returning true
06-23 06:51:40.776: D/ActionBarSherlock(2027): [dispatchCreateOptionsMenu] returning true
06-23 06:51:40.797: D/SherlockFragmentActivity(2027): [onCreatePanelMenu] returning true
06-23 06:51:40.916: D/SherlockFragmentActivity(2027): [onPreparePanel] featureId: 0, view: null, menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:40.916: D/ActionBarSherlock(2027): [dispatchPrepareOptionsMenu] menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:40.916: D/ActionBarSherlock(2027): [callbackPrepareOptionsMenu] menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:40.916: D/Watson(2027): [onPreparePanel] featureId: 0, view: null menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:40.926: D/Watson(2027): [onPreparePanel] activity prepare result: true
06-23 06:51:40.926: D/Watson(2027): [onPreparePanel] fragments prepare result: false
06-23 06:51:40.926: D/Watson(2027): [onPreparePanel] returning true
06-23 06:51:40.926: D/ActionBarSherlock(2027): [callbackPrepareOptionsMenu] returning true
06-23 06:51:40.926: D/ActionBarSherlock(2027): [dispatchPrepareOptionsMenu] returning true
06-23 06:51:40.926: D/SherlockFragmentActivity(2027): [onPreparePanel] returning true
06-23 06:51:41.016: D/SherlockFragmentActivity(2027): [invalidateOptionsMenu]
06-23 06:51:41.016: D/ActionBarSherlock(2027): [dispatchInvalidateOptionsMenu]
06-23 06:51:41.079: D/SherlockFragmentActivity(2027): [onCreatePanelMenu] featureId: 0, menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:41.097: D/ActionBarSherlock(2027): [dispatchCreateOptionsMenu] menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:41.097: D/ActionBarSherlock(2027): [callbackCreateOptionsMenu] menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:41.108: D/Watson(2027): [onCreatePanelMenu] featureId: 0, menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:41.108: D/SherlockFragmentActivity(2027): [getSupportMenuInflater]
06-23 06:51:41.108: D/ActionBarSherlock(2027): [getMenuInflater]
06-23 06:51:41.316: D/Watson(2027): [onCreatePanelMenu] activity create result: true
06-23 06:51:41.316: D/SherlockFragmentActivity(2027): [getSupportMenuInflater]
06-23 06:51:41.316: D/ActionBarSherlock(2027): [getMenuInflater]
06-23 06:51:41.316: D/Watson(2027): [onCreatePanelMenu] fragments create result: false
06-23 06:51:41.316: D/Watson(2027): [onCreatePanelMenu] returning true
06-23 06:51:41.316: D/ActionBarSherlock(2027): [callbackCreateOptionsMenu] returning true
06-23 06:51:41.316: D/ActionBarSherlock(2027): [dispatchCreateOptionsMenu] returning true
06-23 06:51:41.316: D/SherlockFragmentActivity(2027): [onCreatePanelMenu] returning true
06-23 06:51:41.340: D/SherlockFragmentActivity(2027): [onPreparePanel] featureId: 0, view: null, menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:41.352: D/ActionBarSherlock(2027): [dispatchPrepareOptionsMenu] menu: com.android.internal.view.menu.MenuBuilder@41825968
06-23 06:51:41.352: D/ActionBarSherlock(2027): [callbackPrepareOptionsMenu] menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:41.352: D/Watson(2027): [onPreparePanel] featureId: 0, view: null menu: com.actionbarsherlock.internal.view.menu.MenuWrapper@41828208
06-23 06:51:41.388: D/Watson(2027): [onPreparePanel] activity prepare result: true
06-23 06:51:41.388: D/Watson(2027): [onPreparePanel] fragments prepare result: false
06-23 06:51:41.388: D/Watson(2027): [onPreparePanel] returning true
06-23 06:51:41.388: D/ActionBarSherlock(2027): [callbackPrepareOptionsMenu] returning true
06-23 06:51:41.388: D/ActionBarSherlock(2027): [dispatchPrepareOptionsMenu] returning true
06-23 06:51:41.388: D/SherlockFragmentActivity(2027): [onPreparePanel] returning true
06-23 06:51:41.406: D/ActionBarSherlock(2027): [callbackOptionsItemSelected] returning false
06-23 06:51:41.406: D/ActionBarSherlock(2027): [dispatchOptionsItemSelected] returning false
06-23 06:51:41.406: D/SherlockFragmentActivity(2027): [onMenuItemSelected] returning false
06-23 06:51:41.536: I/Choreographer(2027): Skipped 125 frames!  The application may be doing too much work on its main thread.

这是搜索的菜单xml

<item
        android:id="@+id/menu_search"
        android:actionViewClass="android.widget.SearchView"
        android:icon="@drawable/action_search"
        android:showAsAction="ifRoom|collapseActionView"
        android:title="@string/menu_search"/>

1 个答案:

答案 0 :(得分:0)

这是因为功能

supportInvalidateOptionsMenu();
invalidateOptionsMenu();
在onOptionsMenuClosed(),OnOptionsItemSelectedListener(),onOptionsItemSelected()

中调用的

我从这些函数中删除它们并仅将它们放在OnCreate()方法上 并且这些函数的目的是声明选项菜单已更改,因此应重新创建。 onCreateOptionsMenu(Menu)方法将在下次需要显示时调用。