3

「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"/> 

私がする必要があるのは、クラスを使用してこの画像を別のものに変更することです。これは、BaseExpandableListAdapter で拡張された Adapter クラス内で使用したコードです。

if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_details, null);
}
((CheckedTextView) convertView).setCheckMarkDrawable(R.drawable.ic_folder);

しかし、これは使用済みの画像を置き換えるものではありません。代わりに、同じ行に追加されます。現在の画像を新しい画像に置き換えるにはどうすればよいですか?

4

3 に答える 3

5

使用しているxmlで

`android:drawableLeft="@drawable/ic_launcher"`

そしてアダプターであなたがやっている

((CheckedTextView) convertView).setCheckMarkDrawable(R.drawable.ic_folder);

これらは CheckedTextView の 2 つの異なる機能です。CheckMark drawable と drawable は異なる drawable です。CheckedTextViewの左、右、上、下の画像を追加または変更するには、使用する必要があります

CheckedTextView.setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)

また

CheckedTextView.setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom)

CheckMark ドローアブルを変更するCheckedTextView.setCheckMarkDrawable(R.drawable.ic_folder);

于 2014-01-23T08:09:57.143 に答える
1

これは、問題の解決策として私がしたことです。同じ問題に直面した人の助けになることを願っています。ここで、親は ViewGroup パラメータです。

Drawable imageDrawable=parent.getContext().getResources().getDrawable((R.drawable.ic_folder));
 imageDrawable.setBounds(0,0, 40, 40);
((CheckedTextView) convertView).setCompoundDrawables(imageDrawable, null,null, null);
于 2014-01-24T05:14:30.870 に答える
0
Drawable img = getContext().getResources().getDrawable( R.drawable.ic_folder );

((CheckedTextView) convertView).setCompoundDrawables( img, null, null, null );
于 2014-01-23T06:56:41.887 に答える