Reputation: 1167
I have a searchview
and recyclerview
, I share the xml code
<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>
Now I make request to web onQueryTextSubmit(String query)
, I call a function in my adapter class where I do the following
public void filterData(String query){
query=query.toLowerCase();
if(query.isEmpty()){
images.clear();
images.addAll(orignallist);
notifyDataSetChanged();
}
else {
// This is main function
getimages(query);
}
}
I here get images url in a separate thread from the web through jsoup and show it in the recycler view through piccaso, it works perfectly but it only shows when I scroll down a bit , I use this with piccaso in onbindviewholder()
Picasso.get().load(images.get(position)).fit().networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE).centerInside().into(holder.imageView);
How to show image without scrolling , thank you!
When search button clicked , when scrolled down a bit
Update : after adding more functions it is now showing only when the keypad pops up
Upvotes: 0
Views: 128
Reputation: 1167
Problem was that I was trying to use notifydatasetchanged()
inside thread , so I passed activity to the adapter and implemented this :
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
notifyDataSetChanged();
}
});
Images where showing on scrolling or keypad opening because adapter items were getting recycled
Upvotes: 1