【发布时间】:2020-11-13 21:01:52
【问题描述】:
我有一个searchview和recyclerview,我分享xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SearchView
android:id="@+id/searchinput"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:searchIcon="@null"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchinput"
android:layout_alignParentStart="true" />
</RelativeLayout>
现在我向 web onQueryTextSubmit(String query) 发出请求,我在我的适配器类中调用一个函数,并在其中执行以下操作
public void filterData(String query){
query=query.toLowerCase();
if(query.isEmpty()){
images.clear();
images.addAll(orignallist);
notifyDataSetChanged();
}
else {
// This is main function
getimages(query);
}
}
我在这里通过 jsoup 从网络的单独线程中获取图像 url,并通过 piccaso 在回收器视图中显示它,它工作得很好,但它只在我向下滚动一点时显示,我在onbindviewholder() 中将它与 piccaso 一起使用
Picasso.get().load(images.get(position)).fit().networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE).centerInside().into(holder.imageView);
如何在不滚动的情况下显示图像,谢谢!
更新:添加更多功能后,它现在仅在键盘弹出时显示
【问题讨论】:
-
你能添加你的整个适配器代码吗?
-
尝试在两个
if-else条件下添加notifyDataSetChanged,或者你可以在if-else之后做同样的事情(可能是你没有在其他条件下使用notifyDataSetChanged的错误) -
@VivekThummar 我在线程中使用了 notifyDataSetChanged(),我认为这就是问题所在,好的,我会解决它但是为什么在键盘打开时会自动调用 notifyDataSetChanged()?