Android - custom row layout in my ListPreference
Asked Answered
C

1

6

In my Android application, I have implemented class SubtitleColorListPreference which extends from ListPreference. I need this, because I need to set my own layout for each item in list. Everything works fine and it looks like this:

Custom layout in ListPreference

The important code is in method onPrepareDialogBuilder(AlertDialog.Builder builder), where I set my own ListAdapter.

@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
    // some other code is here ...
    ListAdapter listAdapter = new SubtitleColorAdapter(getContext(), R.layout.subtitle_color_preference_item, colorNameHolders, index, this);
    builder.setAdapter(listAdapter, this);
}

Now, I need to use PreferenceFragmentCompat instead of PreferenceFragment, so my SubtitleColorListPreference has to extend android.support.v7.preference.ListPreference. And here is the problem - there are no onPrepareDialogBuilder method in this ListPreference. Also, I did not find any similar method. I tried to find some examples how to create custom android.support.v7.preference.ListPreference, but with no success. Does anybody know how can I solve this?

Community answered 18/12, 2015 at 21:4 Comment(2)
I face the same problem, Did you find any solution?Sarre
I tried to use setOnPreferenceClickListener, and public boolean onPreferenceClick(Preference preference) { Object f = ListPreferenceDialogFragmentCompat.newInstance(preference.getKey()); ListPreferenceDialogFragmentCompat dialogFragment=((ListPreferenceDialogFragmentCompat)f); Dialog dialog= dialogFragment.getDialog(); return false; }, but dialog return nullSarre
H
0

Google thinks that you don't need a custom view in ListPreference. It seems, the only way is to use the deprecated PreferenceFragment and android.preference.ListPreference or stay with obsolete SDK 27. It's clear that they don't understand what they're doing.

Harleyharli answered 3/9, 2018 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.