Ran
Ran

Reputation: 4157

Custom preference not clickable

I added a custom preference to my project (code below). I added it to my preferences xml with a custom widgetLayout:

<w.PlusOnePreference 
    android:title="Rate App"
    android:key="custom"
    android:widgetLayout="@layout/plusone_pref"/>

Preference layout xml:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.plus.PlusOneButton    
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
plus:size="standard" />

I see the layout and the button in the layout works fine. The only problem is that the preference isn't clickable. Like it's hidden behind something.

Any ideas on how to make it clickable?

If I add a regular Preference (without a widget layout) it works fine.

Thanks.

public class PlusOnePreference extends Preference {

private PlusClient mPlusClient = null; 

public PlusOnePreference(Context context) {
    super(context);

}


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

public PlusOnePreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public void setPlusClient(PlusClient plusClient) {
    mPlusClient = plusClient;
}



@Override
protected void onBindView(View view) {
    super.onBindView(view);     
    //mPlusOneButton = 
    PlusOneButton plusOneButton = (PlusOneButton)view.findViewById(R.id.plus_one_button);
    plusOneButton.initialize(mPlusClient, SettingsActivity.URL, SettingsActivity.PLUS_ONE_REQUEST_CODE);
}
  }

Upvotes: 2

Views: 4167

Answers (3)

nmr
nmr

Reputation: 16849

Putting Pskink's answer together with Ran's comment:

  • If your custom preference's layout is a ViewGroup (e.g. a *Layout), use android:descendantFocusability="blocksDescendants"
  • If it's just one View, use android:focusable="false"

Upvotes: 4

pskink
pskink

Reputation: 24730

in layout/plusone_pref.xml set android:focusable="false" for your Button

Upvotes: 8

HannahRose
HannahRose

Reputation: 1

Preferences don't have a clickable attribute, though there is an onClick() method. Tryandroid:selectable.

Upvotes: 0

Related Questions