android-preferences

Adding listeners to individual ListPreference items

让人想犯罪 __ 提交于 2019-12-08 02:06:11
问题 I'm trying to add individual listeners to items in a ListPreference but I just can't find the right code to do it. For example, assume I have an app where needs the region to be set. So I have a ListPreference with three options; Americas, Asia, Europe. When I use the trackpad to scroll through the items I would like them to speak the text of the preference when they get focus. I'm sure somewhere in the API I can add a listener to the individual items but I just can not find it. There is a

save value of spinner selected item using shared preference

瘦欲@ 提交于 2019-12-07 09:05:41
问题 How can I save the current selected spinner value, such that when I reopen the application the saved value is automatically selected by default? My current code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loginpage); final Spinner spinner = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.spinner_array, android.R.layout.simple_spinner_item); adapter

Can't get the PreferenceFragment to work (Compiling error)

孤者浪人 提交于 2019-12-07 06:47:40
问题 I am getting error when i try to compile my project: "The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, FragmentPreferences)". As far as i know, the PreferenceFragment is a Fragment? I am developing for android 4.0 but i have to use android-support-v4 library because my project incluedes also ViewPager. I found this example at http://developer.android.com/guide/topics/ui/settings.html#Fragment: // Display the fragment as the main content.

Change Divider color in Android PreferenceActivity

左心房为你撑大大i 提交于 2019-12-07 05:38:45
问题 Anyone know how to change divider color in Android PreferenceActivity ? 回答1: PreferenceActivity.getListView().setDivider(Drawable divider); Where divider is a drawable that can be a shape , color , gradient , image (png etc). 来源: https://stackoverflow.com/questions/6667367/change-divider-color-in-android-preferenceactivity

How to change state of a preference item from outside the PreferenceActivity?

笑着哭i 提交于 2019-12-07 05:17:39
问题 There are some features in my app which require android version 4.2+. So in my main activity, i will need to check for available OS features and modify(Enable/Disable)preferences items which are defined in my PreferenceActivity . The following code is unreachable from outside the PreferenceActivity ListPreference prefReport = (ListPreference)getPreferenceScreen().findPreference("pref_report"); prefDspProfile.setValue("0"); So my question is how to modify preferences items from outside

NullPointerException when calling RingTonePreference on Samsung Galaxy S

我怕爱的太早我们不能终老 提交于 2019-12-07 01:59:29
问题 I am getting the following message when calling RingTonePreference on Samsung Galaxy (everything works fine on other phones): java.lang.RuntimeException: Unable to start activity ComponentInfo{android/com.a ndroid.internal.app.RingtonePickerActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at android.app.ActivityThread.access$2300(ActivityThread

Android: ListPreference hide/disable value

浪尽此生 提交于 2019-12-07 01:57:06
问题 I'm generating a listPreference dialog based on xml (entries and entryValues). <string-array name="listArray"> <item>Title (A-Z)</item> <item>Title (Z-A)</item> <item>Visits (default)</item> <item>Date</item> <item>Manual</item> </string-array> <string-array name="listValues"> <item>titleASC</item> <item>titleDESC</item> <item>visitsSort</item> <item>createSort</item> <item>manualSort</item> </string-array> I want to hide/disable some of the entries (for example: Manual) based on some other

requestWindowFeature(Window.FEATURE_NO_TITLE); gives the exception

↘锁芯ラ 提交于 2019-12-07 00:44:12
问题 import android.content.pm.ActivityInfo; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.util.Log; import android.view.Window; import android.view.WindowManager; public class OptionsActivity extends PreferenceActivity { private ListPreference mListPreference; @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState);

PreferenceFragment is shown transparently

放肆的年华 提交于 2019-12-06 19:09:37
问题 I'm trying to show a PreferenceFragment after I select the Preferences option in my ActionBar. However, after replacing current content with the PreferenceFragment you can see the old content below it. As in, you can see straight through the preferences. Am I missing something here? I used an example from a book I own, which didn't use any layout files for the preferences. Do you need those? Used code: Actionbar menu private boolean MenuChoice(MenuItem item) { switch (item.getItemId()) { case

How to open AlertDialog from preference screen?

北城以北 提交于 2019-12-06 17:36:34
问题 I am developing Application in android I want to show AlertDialog if user check the checkboxpreference from preference screen. so how i can do that..? 回答1: Override onSharedPreferenceChanged in your PreferenceActivity class: public class MyPreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener { ... public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals("MyCheckboxPreferenceKey")) { //Show your AlertDialog here! } }