在 RecyclerView 上提交查询,图像非常慢且无法正常工作
SubmitQuery on RecyclerView with images very slow and not work correctly
大家好,我用 SearchView
和来自 Web 服务的数据实现了 RecyclerView
,在 SearchView
中,当我清除部分文本或全部文本时,没有更新列表而且执行查询很慢,我按照这个 .
Note : items are contains images !
我的过滤器很简单不复杂:
private ArrayList<itemObj> filter(ArrayList<itemObj> models, String query) {
final ArrayList<itemObj> filteredModelList = new ArrayList<>();
for (itemObj model : models) {
final String text = model.getTitle();
if (text.contains(query)) {
filteredModelList.add(model);
}
}
return filteredModelList;
}
有什么帮助吗?
这里的问题是在你清除搜索文本后,adapter 后面的list 比filter list 小。所以代码需要修改如下
public void addItem(int position, ExampleModel model) {
if(position >= mModel.size()) {
mModel.add(model);
notifyItemInserted(mModel.size()-1);
} else {
mModels.add(position, model);
notifyItemInserted(position);
}
}
并在 moveItem 功能中进行修改
public void moveItem(int fromPosition, int toPosition) {
final ExampleModel model = mModels.remove(fromPosition);
if(toPosition >= mModels.size()) {
mModels.add(model);
notifyItemMoved(fromPosition, mModels.size()-1);
} else {
mModels.add(toPosition, model);
notifyItemMoved(fromPosition, toPosition);
}
}
希望对您有所帮助!
大家好,我用 SearchView
和来自 Web 服务的数据实现了 RecyclerView
,在 SearchView
中,当我清除部分文本或全部文本时,没有更新列表而且执行查询很慢,我按照这个
Note : items are contains images !
我的过滤器很简单不复杂:
private ArrayList<itemObj> filter(ArrayList<itemObj> models, String query) {
final ArrayList<itemObj> filteredModelList = new ArrayList<>();
for (itemObj model : models) {
final String text = model.getTitle();
if (text.contains(query)) {
filteredModelList.add(model);
}
}
return filteredModelList;
}
有什么帮助吗?
这里的问题是在你清除搜索文本后,adapter 后面的list 比filter list 小。所以代码需要修改如下
public void addItem(int position, ExampleModel model) {
if(position >= mModel.size()) {
mModel.add(model);
notifyItemInserted(mModel.size()-1);
} else {
mModels.add(position, model);
notifyItemInserted(position);
}
}
并在 moveItem 功能中进行修改
public void moveItem(int fromPosition, int toPosition) {
final ExampleModel model = mModels.remove(fromPosition);
if(toPosition >= mModels.size()) {
mModels.add(model);
notifyItemMoved(fromPosition, mModels.size()-1);
} else {
mModels.add(toPosition, model);
notifyItemMoved(fromPosition, toPosition);
}
}
希望对您有所帮助!