-
-
Save trinhduyhung/ba6ab2ec7c2dfb4d91ce0c9b9f5621eb to your computer and use it in GitHub Desktop.
Revisions
-
Sloy created this gist
Jun 29, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ package com.your.package; import android.content.Context; import android.preference.ListPreference; import android.util.AttributeSet; /** * Created by Rafa Vázquez on 29/06/13. * * ListPreference item that shows its selected value as summary. * Use in the XML just like the normal ListPreference. * * License: * ------------------------------------------------- * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ public class AutoSummaryListPreference extends ListPreference { public AutoSummaryListPreference(Context context) { this(context, null); } public AutoSummaryListPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); if (positiveResult) { setSummary(getSummary()); } } @Override public CharSequence getSummary() { int pos = findIndexOfValue(getValue()); return getEntries()[pos]; } }