我正在尝试在标题栏中搜索
我有ListView
和GridView
以及方法switchView()
,可以在这两种模式之间切换。我按ArrayList
添加了项目。我想在搜索栏中搜索该项目
我在MainActivity中使用了这段代码
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main2, menu);
MenuItem item = menu.findItem(R.id.app_bar_search);
SearchView searchView = (SearchView)item.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
listViewAdapter.getFilter().filter(newText);
gridViewAdapter.getFilter().filter(newText);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
当我运行该程序时,会显示一条消息不幸的是我的应用已停止。当我删除上面的中的代码并使其return false
应用程序正常工作但当然没有搜索。
这是logcat调试和错误
10-29 14:13:28.681 951-951/? I/ServiceManager: service 'SurfaceFlinger' died
10-29 14:13:28.709 951-951/? I/ServiceManager: service 'simphonebook' died
10-29 14:13:28.709 951-951/? I/ServiceManager: service 'iphonesubinfo' died
10-29 14:13:28.709 951-951/? I/ServiceManager: service 'isms' died
10-29 14:13:28.709 951-951/? I/ServiceManager: service 'phone' died
10-29 14:13:28.709 951-951/? I/ServiceManager: service 'carrier_config' died
10-29 14:13:28.709 951-951/? I/ServiceManager: service 'isub' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'telecom' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'search' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'dropbox' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'wallpaper' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'input_method' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'accessibility' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'mount' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'uimode' died
10-29 14:13:28.748 951-951/? I/ServiceManager: service 'lock_settings' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'deviceidle' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'device_policy' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'statusbar' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'clipboard' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'network_management' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'textservices' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'network_score' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'netstats' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'netpolicy' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'wifip2p' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'wifi' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'wifiscanner' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'rttmanager' died
10-29 14:13:28.749 951-951/? I/ServiceManager: service 'ethernet' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'connectivity' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'servicediscovery' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'updatelock' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'notification' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'devicestoragemonitor' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'location' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'country_detector' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'imms' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'audio' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'DockObserver' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'midi' died
10-29 14:13:28.750 951-951/? I/ServiceManager: service 'usb' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'serial' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'user' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'procstats' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'meminfo' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'gfxinfo' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'dbinfo' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'cpuinfo' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'permission' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'processinfo' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'sensorservice' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'jobscheduler' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'backup' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'appwidget' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'voiceinteraction' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'diskstats' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'samplingprofiler' died
10-29 14:13:28.751 951-951/? I/ServiceManager: service 'commontime_management' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'dreams' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'assetatlas' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'graphicsstats' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'print' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'restrictions' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'battery' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'media_session' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'usagestats' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'webviewupdate' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'scheduling_policy' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'telephony.registry' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'media.camera.proxy' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'account' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'content' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'vibrator' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'consumer_ir' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'alarm' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'window' died
10-29 14:13:28.752 951-951/? I/ServiceManager: service 'input' died
10-29 14:13:28.753 964-1644/? W/AudioFlinger: power manager service died !!!
10-29 14:13:28.755 972-972/? D/fingerprintd: binder died
10-29 14:13:28.755 972-972/? D/FingerprintHal: ----------------> fingerprint_close ----------------->
10-29 14:13:28.758 965-965/? E/installd: eof
10-29 14:13:28.758 965-965/? E/installd: failed to read size
10-29 14:13:28.758 965-965/? I/installd: closing connection
10-29 14:13:28.758 950-950/? I/lowmemorykiller: ActivityManager disconnected
10-29 14:13:28.758 950-950/? I/lowmemorykiller: Closing Activity Manager data connection
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'media_router' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'trust' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'fingerprint' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'batterystats' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'appops' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'power' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'display' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'launcherapps' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'media_projection' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'package' died
10-29 14:13:28.760 951-951/? I/ServiceManager: service 'activity' died
logcat erro
10-29 14:13:28.758 965-965/? E/installd: eof
10-29 14:13:28.758 965-965/? E/installd: failed to read size
答案 0 :(得分:0)
这一定是您的模式的问题,因为您说一次应该有一种模式,它将从该特定的选定模式进行搜索。但在你的情况下,你正在搜索两者。您正在获得过滤器和搜索。希望有所帮助