I create small app to show my problem. You can see it here https://github.com/Anton111111/ExampleGlideBlink.
public class MainActivity extends AppCompatActivity {
private Adapter adapter;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView rv = (RecyclerView) findViewById(R.id.recycler_view);
rv.setHasFixedSize(true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
rv.setLayoutManager(gridLayoutManager);
ArrayList<String> items = new ArrayList<>(Arrays.asList(new String[]{
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20"
}));
adapter = new Adapter(this, items);
rv.setAdapter(adapter);
handler = new Handler();
handler.postDelayed(r, 500);
}
Runnable r = new Runnable() {
@Override
public void run() {
Random rand = new Random(System.currentTimeMillis());
handler.postDelayed(r, 500);
adapter.notifyItemChanged(rand.nextInt(4));
}
};
public class Adapter extends RecyclerView.Adapter {
private final Context ctx;
private ArrayList<String> items = new ArrayList<>();
private int progress = 1;
public Adapter(Context context, ArrayList<String> items) {
this.items = items;
ctx = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item, parent, false);
Holder h = new Holder(v);
return h;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((Holder) holder).getProgress().setText(progress+"");
progress++;
Glide.with(ctx)
.load(Uri.parse("file:///android_asset/" + (position + 1) + ".png"))
.into(((Holder) holder).getImage1());
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return items.size();
}
public class Holder extends RecyclerView.ViewHolder {
private final ImageView image1;
private final TextView progress;
public ImageView getImage1() {
return image1;
}
public TextView getProgress() {
return progress;
}
public Holder(View itemView) {
super(itemView);
image1 = (ImageView) itemView.findViewById(R.id.image1_view);
progress = (TextView) itemView.findViewById(R.id.progress_text);
}
}
}
}
Main Layout: https://github.com/Anton111111/ExampleGlideBlink/blob/master/app/src/main/res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.testglide.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Item Layout: https://github.com/Anton111111/ExampleGlideBlink/blob/master/app/src/main/res/layout/item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/image1_view"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:id="@+id/progress_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
When i call notifyItemChanged on RecyclerView adapter i need change only text (in my example it EditText with id R.id.progress) and image shown without changes. But it blink.
Have i ability to change text without blinking?