dror
dror

Reputation: 3946

Preference.setWidgetLayoutResource() issue

I'm trying to set an icon image of a clickable Preference, after returning from an image picker (to show the user what he/she has selected).

A simple setup like so doesn't work and I don't know why:

public boolean onActivityResult(int requestCode, int resultCode, Intent intent) {
    mIconPathPreference.setWidgetLayoutResource(R.layout.preference_icon);
}

Especially when putting the line setWidgetLayoutResource in other places does adds an icon.

preference layout:

<Preference
    android:key="@string/iconPath_key"
    android:title="@string/iconPath"
    android:summary="@string/iconPath_summ"
    android:dependency="@string/iconEnable" />

preference_icon layout:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:src="@drawable/ic_launcher" />

Upvotes: 0

Views: 2053

Answers (1)

Guan Hao
Guan Hao

Reputation: 136

Set the android:widgetLayout attribute for your preference should work.

<Preference
    android:key="@string/iconPath_key"
    android:title="@string/iconPath"
    android:summary="@string/iconPath_summ"
    android:dependency="@string/iconEnable"
    android:widgetLayout"@layout/your_widge_layout" />

Upvotes: 6

Related Questions