'Recyclerview fast scroll items disappear
I am using GridLayoutManager with recyclerview, when i fast
scroll down one item out of four visible grid items (bottom right ) is moved further down,
I am using this tutorial to implement fast scroll and fast scroll indicator here
Solution 1:[1]
Guess i've found the solution.
Looks like when the Recycled Views are attached to the Window again, their state is changed to Invisible (IDK why). All we have to do is make it visible again.
Fortunately, RecyclerView.Adapter class has a method to handle when a view is attached or reattached to the RecyclerView.
@Override
public void onViewAttachedToWindow(ViewHolder holder){
super.onViewAttachedToWindow(holder);
if(!holder.tv_1.getText().toString().contentEquals("#EMPTYVIEW"))
holder.root.setVisibility(View.VISIBLE);
Log.i("ATTACHED_VISIBILITY",holder.tv_1.getText().toString()+"\t"+holder.root.getVisibility());
}
My ViewHolder class
class ViewHolder extends RecyclerView.ViewHolder{
TextView tv_1;
TextView tv_2;
ImageView iv;
ImageButton bt;
View root;
ViewHolder(View v){
super(v);
//setIsRecyclable(false); //to prevent views from getting deleted. :-(
tv_1=(TextView)v.findViewById(R.id.aral_tv_title);
tv_2=(TextView)v.findViewById(R.id.aral_tv_stitle);
iv=(ImageView)v.findViewById(R.id.aral_iv);
bt=(ImageButton)v.findViewById(R.id.aral_bt_more);
tv_1.setTypeface(WorkActivity.mainTF);
tv_2.setTypeface(WorkActivity.mainTF);
root=v;
}
}
Hope this helps you out.
Solution 2:[2]
For every if there should be else.
For example:
If you have a view which is visible in XML file by default but you are changing its visibility in code, you must supply the else otherwise RecyclerView will re-use the views and will show re-used views with different data.
if(somethingIsTrue) {
view.setVisibility(View.GONE);
} else {
view.setVisibility(View.VISIBLE);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | KRUPEN GHETIYA |
