0

プログラムでリストアイテムのビューを作成しようとしています-元のAndroidチェックボックステンプレートに類似している必要があります-Androidの元のテンプレートxmlは次のとおりです。

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/textCheckMark"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>

これが私の情報源です:

CheckedTextView ctv = new CheckedTextView(context);
ctv.setId(CTV_ID);
ctv.setCheckMarkDrawable(android.R.attr.textCheckMark);
ctv.setPadding(Utils.toDP(4, context), Utils.toDP(4, context), Utils.toDP(4, context), Utils.toDP(4, context));

問題はsetCheckMarkDrawable回線にあります。例外が発生します。

android.content.res.Resources$NotFoundException: Resource ID #0x1010046

私のコードがこのリソースにアクセスできないことは明らかです。私は何をすべきか、私は何を間違っているのか、これを修正する方法は?

4

1 に答える 1

2

OK、解決策を見つけました:

TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.textCheckMark, typedValue, true);
return typedValue.resourceId; // <- This is the actual resource id to be used

この値は、現在のテーマリソースIDに解決する必要があるようです。同様の問題:スタイルとテーマの背景の問題

于 2013-03-25T22:38:35.353 に答える