I´m a beginner and would like to know which one of setImageBitmap vs setImageResource vs setImageDrawable is best practice for changing between two appearances (states) of an ImageButton in Recycler List View. Just like the clock symbol in Androids AlarmClock which has 2 different states and is located in an RecyclerView: I need 10 reputation to post images so here´s a website with a picture of an alarm list: https://www.pctipp.ch/androidtipp/artikel/android-coole-wecker-features-in-samsung-und-aehnlichen-smartphones-81200/
I already found an accepted answer for a similar case: setImageResource Vs setDrawable It says setImageResource may be the worst solution but if I take the other solutions my ImageButton has problems for example it loses its former size. What is more it looks like it has to be done a lot more for example "decodeResource". I think it´s not good for its performance because it´s executed for every row. I know that setImageDrawable is always called when setImageBitmap so I think setImageBitmap wouldn´t be the right answer.
This code is part of my onBindViewHolder in my RecyclerView´s Adapter:
if (alarmAtPosition.isActive()){
//Bitmap bm = BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.ic_access_alarms_black_24dp);
Drawable myDrawable = Resources.getSystem().getDrawable(R.drawable.ic_access_alarms_black_24dp);
viewHolder.imageButton.setImageDrawable(myDrawable);
//viewHolder.imageButton.setImageResource(R.drawable.ic_access_alarms_black_24dp);
}
else {
//Bitmap bm2 = BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.ic_settings_black_24dp);
Drawable myDrawable2 = Resources.getSystem().getDrawable(R.drawable.ic_settings_black_24dp);
viewHolder.imageButton.setImageDrawable(myDrawable2);
//viewHolder.imageButton.setImageResource(R.drawable.ic_settings_black_24dp);
}
In my row.xml I don´t need to put android:src="@drawable/ic_settings_black_24dp
if I use setImageResource. So it would be a lot easier for me to take this solution but that accepted answer is making me uncertain. Please tell me: Which one is for best performance?