I set image icon in layout using "android:drawableLeft". This is my layout code:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textView1"
android:layout_marginLeft="8dp"
android:drawableLeft="@drawable/ic_launcher"
android:gravity="left"/>
What I need to do is, change this image into something else using my class. This is the code I used inside my Adapter class which is extend with BaseExpandableListAdapter.
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_details, null);
}
((CheckedTextView) convertView).setCheckMarkDrawable(R.drawable.ic_folder);
But this is not replace the used image. Instead replacing it is added to the same line. What should I do to replace the current image with the new one?
This is what I did as the solution for the problem. Hope it will help anyone who faced the same problem. Here parent is ViewGroup parameter,
Drawable imageDrawable=parent.getContext().getResources().getDrawable((R.drawable.ic_folder));
imageDrawable.setBounds(0,0, 40, 40);
((CheckedTextView) convertView).setCompoundDrawables(imageDrawable, null,null, null);