首页 > 解决方案 > 毕加索在滚动后显示图像

问题描述

我有一个searchviewand 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 在回收站视图中显示它,它工作得很好,但它只在我向下滚动一点时显示,我在 piccaso 中使用它onbindviewholder()

Picasso.get().load(images.get(position)).fit().networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE).centerInside().into(holder.imageView);

如何在不滚动的情况下显示图像,谢谢!

单击搜索按钮在此处输入图像描述时,向下滚动一点时在此处输入图像描述

更新:添加更多功能后,它现在仅在键盘弹出时显示

标签: androidpicasso

解决方案


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

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

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


推荐阅读