user1041858
user1041858

Reputation: 957

Click on Text and Checkbox separately in CheckBoxPreference

I am creating a PreferenceActivity by using the PreferenceScreen xml. I wants to open a new preference screen when click on the label(title) of a CheckBoxPreference and when the user click on check box of this CheckBoxPreference then normal preference functionality will work. So how can I do it?

For Example: Change a user profile(by click on radio buttons) and changing its properties(by clicking on label of this radio button) in android

Upvotes: 1

Views: 305

Answers (1)

koji
koji

Reputation: 11

I think it's hard to do with a default preference. But you can try extending the original onBindView method, according to the documentation: This is a good place to grab references to custom Views in the layout and set properties on them. So, this is an example for CheckBoxPreference to be clickable on text.

public class MyCheckBoxPreference extends CheckBoxPreference {
    static final String TAG = "MyCheckBoxPreference";

    public MyCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MyCheckBoxPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyCheckBoxPreference(Context context) {
        super(context);
    }

    @Override
    protected void onBindView(View v) {
        super.onBindView(v);
        ((ViewGroup) v).getChildAt(1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick " + getKey());
            }
        });
    }
}

Upvotes: 1

Related Questions