无法在正确的位置单击搜索视图项目


private ListView lvProduct;
private ListProductAdapter adapter;
private List<Product> mProductList;
private DatabaseHelper mDBHelper;     
adapter = new ListProductAdapter(this, mProductList);
lvProduct.setAdapter(adapter);
@Override
public void onItemClick(AdapterView<?> parent, View view, int 
position2, long id) {
}
});

**这里是搜索查询列表器**

@Override
public boolean onQueryTextChange(String s) {
s=s.toLowerCase();
ArrayList<Product> newList = new ArrayList<>();
for (Product listProductAdapter : mProductList){
String name = listProductAdapter.getSearchName().toLowerCase();
if(name.contains(s)){
newList.add(listProductAdapter);
;
}
}
adapter.setFilter(newList);
return true;
}

这是列表适配器和过滤器适配器

public ListProductAdapter(Context mContext, List<Product> mProductList) {
this.mContext = mContext;
this.mProductList = mProductList;
}

@Override
public int getCount() {
return mProductList.size();
}

@Override
public Object getItem(int position) {
return mProductList.get(position);
}
@Override
public long getItemId(int position2) {
return mProductList.get(position2).getId();
}

@Override
public View getView(int position2, View convertView, ViewGroup parent) {
View v = View.inflate(mContext, R.layout.item_listview, null);
v.setTag(mProductList.get(position2).getId());
TextView tvName = (TextView)v.findViewById(R.id.tv_product_name);
tvName.setText(mProductList.get(position2).getName());
return v;
}
public void setFilter(ArrayList<Product> newList){
mProductList = new ArrayList<>();
mProductList.addAll(newList);
notifyDataSetChanged();
}

我想使用mProductList.get(position2(.getId((单击项目我正在为搜索视图获得一个排序的新适配器,但我正在获得以前的适配器位置 ID。但是我想要一个更新的列表视图位置 ID 和更新的列表视图适配器。请帮助我。

您需要清除旧列表并添加新项目。 试试这个,

public void setFilter(ArrayList<Product> newList){
mProductList.clear();
mProductList.addAll(newList);
notifyDataSetChanged();
}

最新更新