【问题标题】:Picasso showing images after scrolling毕加索在滚动后显示图像
【发布时间】:2020-11-13 21:01:52
【问题描述】:

我有一个searchviewrecyclerview,我分享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()?

标签: android picasso


【解决方案1】:

问题是我试图在线程内使用notifydatasetchanged(),所以我将活动传递给适配器并实现了这个:

activity.runOnUiThread(new Runnable() {
@Override
 public void run() {
 notifyDataSetChanged();
 }
 });

由于适配器项目被回收而在滚动或键盘打开时显示的图像

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多