我在动作栏上实现了Android的SearchView搜索列表视图,一切正常,但SearchView中查询的文本显示如下
这是我写的代码
searchView.setQueryHint("Query Hint");
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(this);
任何人都可以帮我解决一下如何删除该视图
这是有关搜索视图的代码。
public class HomeScreen extends Activity implements SearchView.OnQueryTextListener{
....
OnCreate(){
...
listView.setAdapter(adapter);
listView.setTextFilterEnabled(true);
}
OnCreateOptionsMenu()
{...
setUpSearchView();
...}
private void setupSearchView() {
searchView.setQueryHint("Search Product");
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(this);
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
listView.clearTextFilter();
} else {
listView.setFilterText(newText);
}
return true;
}
适配器代码如下。
public class CustomListAdapter extends BaseAdapter implements Filterable{
private Activity activity;
private List<Product> productItems;
private List<Product> orig;
public CustomListAdapter(Activity activity, List<Product> productItems) {
this.activity = activity;
this.productItems = productItems;
}
@Override
public int getCount() {
return productItems.size();
}
@Override
public Object getItem(int location) {
return productItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ProductHolder productHolder;
....
return convertView;
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
final FilterResults filterResults = new FilterResults();
final List<Product> intermediateResults = new ArrayList<Product>();
if(orig == null)
orig = productItems;
if(constraint != null)
{
if(orig!=null && orig.size() > 0){
for (final Product g : orig) {
if (g.getTitle().toLowerCase().contains(constraint.toString()))
intermediateResults.add(g);
}
}
filterResults.values = intermediateResults;
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
productItems = (ArrayList<Product>) results.values;
notifyDataSetChanged();
}
};
}
}