1

ここにある IconPreferenceScreen クラスを使用して、右側に削除アイコンがある設定リストを作成しています。

これは私が使用したコードです:

protected void updateFavoritesCategory() {
        PreferenceCategory favsCategory = (PreferenceCategory) findPreference("pref_category_favs");
        favsCategory.removeAll();

        List<Favorite> favs = myAppDB.getFavorites();

        for (Favorite f : favs) {

            String stName = StringUtils.unescapeHTML(f.getName());
            stName = URLDecoder.decode(stName);

            IconPreferenceScreen favPreference = new IconPreferenceScreen(this, R.drawable.ic_delete, f.getId().toString());
            favPreference.setIconClickedListener(this);
            favPreference.setTitle(stName);
            favsCategory.addPreference(favPreference);
        }

    }

このコードは Gingerbread で問題なく動作します。

ここに画像の説明を入力

ご覧のとおり、タイトル、概要、アイコンが表示されますが、ICS+ デバイスでは空白のエントリが表示され、テキストもアイコンもまったく表示されず、各要素をクリックしても強調表示されません。

ここに画像の説明を入力

これは、各リスト要素の XML です。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+android:id/widget_frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:gravity="center_vertical"
    android:minHeight="56dp"
    android:padding="10dp"
    android:paddingEnd="?android:attr/scrollbarSize" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:contentDescription="@null"
        android:src="@drawable/ic_delete" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignBottom="@+id/icon"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/icon"
        android:gravity="center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:text="Name"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="12sp" />

    </LinearLayout>

</RelativeLayout>

なぜこれが起こっているのかについてのアイデアはありますか?

PS: 簡単に参照できるように、IconPreferenceScreen クラスを次に示します。ユーザーがアイコンをクリックしたときのイベントリスナーを追加するために少し変更しました。

public class IconPreferenceScreen extends Preference implements OnClickListener {

    private final Drawable mIcon;
    private static String mType;
    private Context mContext;

    private String tag = "";
    private IconClickedListener iconClickedListener;

    public interface IconClickedListener
    {
        public void onClick(String tag);
    }



    public IconPreferenceScreen(Context context, AttributeSet attrs, int iconRes) {
        this(context, attrs, 0, iconRes);
    }

    public IconPreferenceScreen(Context context, AttributeSet attrs, int defStyle, int iconRes) {
        super(context, attrs, defStyle);
        mContext = context;
        setLayoutResource(R.layout.preference_icon);
        mIcon = context.getResources().getDrawable(iconRes); 
    }

    public IconPreferenceScreen(Context context, int iconRes, String tag) {
        this(context, null, iconRes);
        mContext = context;
        this.tag = tag;
    }

    @Override
    public void onBindView(View view) {
        super.onBindView(view);

        ImageView imageView = (ImageView) view.findViewById(R.id.icon);
        imageView.setOnClickListener(this);
        if (imageView != null && mIcon != null) {
            imageView.setImageDrawable(mIcon);
        }
    }

    @Override
    public void onClick(View v) {
        iconClickedListener.onClick(tag);
    }

    public IconClickedListener getIconClickedListener() {
        return iconClickedListener;
    }

    public void setIconClickedListener(IconClickedListener iconClickedListener) {
        this.iconClickedListener = iconClickedListener;
    }
}
4

0 に答える 0