我使用“ android:drawableLeft”在布局中设置图像图标。这是我的布局代码:
<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"/>
我需要做的是,使用我的班级将此图像更改为其他图像。这是我在Adapter类中使用的代码,该类通过BaseExpandableListAdapter进行了扩展。
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_details, null);
}
((CheckedTextView) convertView).setCheckMarkDrawable(R.drawable.ic_folder);
但这不是替换使用的图像。而是将其替换添加到同一行。我应该怎么做才能用新的图像替换当前的图像?
这就是我作为解决问题的方法。希望它能对遇到同样问题的任何人有所帮助。这里的parent是ViewGroup参数,
Drawable imageDrawable=parent.getContext().getResources().getDrawable((R.drawable.ic_folder));
imageDrawable.setBounds(0,0, 40, 40);
((CheckedTextView) convertView).setCompoundDrawables(imageDrawable, null,null, null);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句