I want to group some self-define Style in PreferenceScreen, So I
insert another layer for this group.
Before the group inserted, everything is work fine and it looks like
"Settings" in Android.

What I did is move the self-define style Items from main view to my
group view, and this group view located in main view.
xmls as followng:
1. mainview.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android";
    android:title="@string/my_label"
     android:key="parent"
>
        <com.android.settings.MyGroupPreference
                android:width="400dip">
        </com.android.settings.MyGroupPreference>
</PreferenceScreen>

2. inserted mygroupview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/
android"
                        android:id="@+android:id/preference_group"
                android:background="@drawable/panel_bg_background"
                android:gravity="center_vertical"
                android:layout_width="fill_parent"
                android:layout_height="100.0dip"
                android:layout_margin="10.0dip"
                android:paddingRight="?android:attr/scrollbarSize"
                >

        <!-- Item A -->
        <com.android.mine.ItemPreferenceScreen
                  settings:icon="@drawable/ic_item_A"
            android:title="@string/item_A_title">
            <intent
                android:action="android.intent.action.MAIN"
                android:targetPackage="com.android.mine"
                android:targetClass="com.android.mine.ItemA" />
        </com.android.mine.IconPreferenceScreen>

        <!-- Item B -->
        <com.android.mine.ItemPreferenceScreen
            settings:icon="@drawable/ic_Item_B"
            android:title="@string/Item_B_title">
            <intent
                android:action="android.intent.action.MAIN"
                android:targetPackage="com.android.mine"
                android:targetClass="com.android.mine.ItemB" />
        </com.android.mine.ItemPreferenceScreen  >
</RelativeLayout >

3. item_perference_screen.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:id="@+android:id/widget_frame"
    android:layout_width="match_parent"
    android:layout_height="40dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
   >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="6dip"
        android:layout_marginTop="6dip"
        android:layout_marginBottom="6dip"
        android:layout_weight="1">

        <TextView android:id="@+android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@+android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/title"
            android:layout_alignLeft="@android:id/title"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:maxLines="2" />

    </RelativeLayout>


    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dip"
        android:layout_marginRight="6dip"
        android:layout_gravity="center" />

</LinearLayout>

java code:
1. main Class
public class MainViewActivityextends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.mainview);
        getListView().setBackgroundResource(R.color.white);

        PreferenceGroup parent = (PreferenceGroup)
findPreference(KEY_PARENT);
        Utils.updatePreferenceToSpecificActivityOrRemove(this, parent,
KEY_SYNC_SETTINGS, 0);
    }
};

2. inserted group Class
public class MyGroup extends Preference {

    //private Drawable mIcon;
    public MyGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        setLayoutResource(R.layout.mygroupview);
    }

};

3. item class
public class ItemPreferenceScreen  extends Preference {

    private Drawable mIcon;

    public ItemPreferenceScreen  (Context context, AttributeSet attrs)
{
        this(context, attrs, 0);
    }

    public ItemPreferenceScreen  (Context context, AttributeSet attrs,
int defStyle) {
        super(context, attrs, defStyle);
        setLayoutResource(R.layout.item_perference_screen);
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.IconPreferenceScreen, defStyle, 0);
        mIcon = a.getDrawable(R.styleable.ItemPreferenceScreen_icon);
    }

    @Override
    public void onBindView(View view) {
        super.onBindView(view);
        ImageView imageView = (ImageView)
view.findViewById(R.id.icon);
        if (imageView != null && mIcon != null) {
            imageView.setImageDrawable(mIcon);
        }
    }
}

After I insert this group view, it report run-time error
android.view.InflateException: Binary XML file line #13: Error
inflating class...

Anybody know what's the problem?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to