Home Ask Login Register

Developers Planet

Your answer is one click away!

skippy February 2016

Android PreferenceScreen and Preference widget instance access

In my app exist my own class

public class ColorAccesoryView extends View{
    @Override protected void onDraw(Canvas cv){
    }
}

used in layout color_accesory.xml

<?xml version="1.0" encoding="utf-8"?>
<android.swp.ColorAccesoryView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/color_box"
android:layout_width="52dp"
android:layout_height="26dp"
android:gravity="right"
android:paddingRight="12dp" />

While PreferenceScreen create, I set this xml as a widget in two different preferences

color1_Pref.setWidgetLayoutResource(R.layout.color_accesory);
...
color2_Pref.setWidgetLayoutResource(R.layout.color_accesory);

How to get access to two instances of ColorAccesoryView to setup it for each preference separatelly?

Answers


miha_dev February 2016

Try wrap your layout color_accesory.xml in group view element:

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <android.swp.ColorAccesoryView 
            android:id="@+id/color_box"
            android:layout_width="52dp"
            android:layout_height="26dp"
            android:gravity="right"
            android:paddingRight="12dp" />
</FrameLayout>

Post Status

Asked in February 2016
Viewed 1,459 times
Voted 14
Answered 1 times

Search




Leave an answer


Quote of the day: live life