Is there a way to keep the dividers around a non selectable preference?

1.5k Views Asked by At

If you set the selectability of a preference item to false, you will notice that the dividers around that item will disappear.

Do you know if there is a way to keep those dividers?

I have looked at the ListView API and could not find a solution that could be applied here, since there is no selectable attribute for ListView items (except for the headers and footers).

Thanks!

5

There are 5 best solutions below

1
longi On

some example code would help! did you set your dividers in the ListView element? if yes check this post as well.

<ListView
    //...
    android:divider="@color/black"
    />

Otherwise you could create a custom ListElementView and add your dividers in the layout xml.

1
Dave Aaron Smith On

I did it with a hack.

<Preference android:layout="@layout/preference_divider" />
<Preference android:title="@string/whatever" android:selectable="false" />

res/layout/preference_divider.xml

<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#cccccc"
    android:layout_width="fill_parent"
    android:layout_height="1px" />
0
StefanMK On

Here is a "trick" that worked for me. Simply set android:focusable="true" to any of the items inside the preference. This will make the whole preference line not clickable.

0
Benjamin Bisinger On

If you want to use the preference to show some text you can also use an uneditable EditTextPreference. The preference will still be selectable but only shows its content when selected.

<EditTextPreference
    android:editable="false"
    ... />
0
Ahmer Afzal On

The line you want to hide is called 'divider'. PreferenceActivity extends ListActivity and as you may expect it uses ListView. You can change a divider in a ListView. In your PreferenceActivity:

        ListView lv = getListView();
        lv.setDivider(new ColorDrawable(Color.TRANSPARENT));
        lv.setDividerHeight(0);