I checked different options that are available in PreferenceScreen (eg. CheckBoxPreference, EditTextPreference, etc.) but non of them give me the possiblity to obtain a simple dialog with just 2 buttons. I would like to use it to implement a basic “Yes, reset my app” / “Cancel” features. How to make this preference option easily?
Asked
Active
Viewed 247 times
0
-
The Preference widgets are limited. You can use a ListPreference (with 2 item to simulate your 2 buttons) or try to build your own custom Preference, extending some existing one. – Phantômaxx Feb 26 '14 at 11:01
-
Check out http://stackoverflow.com/questions/5127407/how-to-implement-a-confirmation-yes-no-dialogpreference – Madhur Ahuja Feb 26 '14 at 11:02
-
Artoo Detoo, for me ListPreference with 2 items does not look good. Madhur Ahuja I checked the link now but I don't know how to solve com.android.internal.R.attr.yesNoPreferenceStyle error in code. – Annabelle Feb 26 '14 at 11:05
1 Answers
1
Its tricky check this answer. Well I've implemented EditText Preference which shows 2 buttons ok and cancel but in middle there is Edittext.
-
This seems to be exactly what I need! But I have one problem in adding the original soure code from the given link. In constructor I get the error in line with "com.android.internal.R.attr.yesNoPreferenceStyle". How can I fix it? – Annabelle Feb 26 '14 at 11:38
-
1@Annabelle: gotcha it working fine now. I want you to create another pacakage name it "com.android.internal.preference". Create new class in it and paste that code inside it. Now just comment 2nd and 3rd YesNoPreference constructor. – kevz Feb 26 '14 at 11:58
-
I found a different solution: I added justa a Preference option, I implemented onPreferenceClick and in onClick I created new AlertDialog.Builder. It's not perfect ideal solution, but works. – Annabelle Feb 26 '14 at 12:10
-