android-preferences

Get Key, not value, of the ListPreference selection - Possible?

隐身守侯 提交于 2019-12-05 15:05:50
Getting the value of the currently selected item in a ListPreference is straightforward: String selected = sharedPrefs.getString( getString(R.string.list_preference_array), "default string" ); But now I need to get the key of the currently selected item, instead. Is this possible? To clarify, a typical ListPreference definition in the XML file has the following components: <ListPreference android:key="@string/list_preference_array" android:title="Title of ENTIRE list (not seen by user?)" android:summary="this is what the user sees in small fonts" android:defaultValue="just in case" android

Separate preferences for each view in an Android app

亡梦爱人 提交于 2019-12-05 14:54:13
I have multiple views that come and go as the application runs. I want each view to have its own personal preferences that are stored as the ID tag of the view. Above these is the "General Preferences" that the sub prefs reference to get their default values when a view it is created. Right now I have it set up that the General Preferences are the default SharedPreferences. But I have no Idea how to create the new preferences and set up an activity UI so the user can change them. Is it pretty much the same as setting up the SharedPreferences? this may not be exactly what you're asking for, but

Change height of Preference items

不问归期 提交于 2019-12-05 13:38:09
I have a PreferenceFragment subclass. I want each one of its items (Preferences and SwitchPreferences) to have a height of 120dp. How to do that? Here is the related code: public class SettingsFragment extends PreferenceFragment { public SettingsFragment() {} @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.main); } } and <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <SwitchPreference android:key="app_main_switch" android:title="@string/app_name

How to return from preference screen to main activity?

依然范特西╮ 提交于 2019-12-05 09:57:30
I have one main activity and one preferenceActivity. On my first activity I call menu and go on preferenceActivity by calling startActivityForResult. case R.id.settings: startActivityForResult(new Intent(this, SettingsActivity.class), LAUNCH_SETTINGS); return true; Then I change my settings and want to return on main activity and see main activity with new settings applyed. In onPause() method do following (as I right understand this method will be called when I press back button, right?) @Override protected void onPause() { super.onPause(); setResult(RESULT_OK, new Intent(this, MainActivity

Custom inline SeekBarPreference - how to set SeekBar progress on the 1st run?

纵然是瞬间 提交于 2019-12-05 09:32:08
I have prepared a simple test project for my question at GitHub. In my project there is a custom inline SeekBarPreference , which mostly works fine (its summary is updated when seekbar is being dragged and it saves integer value): However there is a problem: On the very 1st run of the app (you might need to uninstall my app when you try see the error again) the progress of the SeekBar is not set (but the summaries are set): My question is: how to fix this issue in my code? I have tried adding mSeekBar.setProgress(mProgress) in different spots of SeekBarPreference.java , but just can't find the

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

这一生的挚爱 提交于 2019-12-05 08:50:25
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. getFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit

requestWindowFeature(Window.FEATURE_NO_TITLE); gives the exception

人走茶凉 提交于 2019-12-05 05:21:32
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); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); requestWindowFeature(Window.FEATURE_NO_TITLE);

Custom preference not clickable

烂漫一生 提交于 2019-12-05 04:56:26
问题 I added a custom preference to my project (code below). I added it to my preferences xml with a custom widgetLayout: <w.PlusOnePreference android:title="Rate App" android:key="custom" android:widgetLayout="@layout/plusone_pref"/> Preference layout xml: <?xml version="1.0" encoding="utf-8"?> <com.google.android.gms.plus.PlusOneButton xmlns:android="http://schemas.android.com/apk/res/android" xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus" android:id="@+id/plus_one

How to load the same screen preference in the detail PreferenceFragment

﹥>﹥吖頭↗ 提交于 2019-12-05 04:51:38
I am trying to do something like the settings preferences in android for tablet. When I click the "More" the the "Wireless & Networks" preferences screen is displayed on the right fragment, than if I touch the "VPN" , in the same fragment the "VPN" preferences screen is opened. How can I do that ? this is my preference xml <PreferenceScreen android:title="Title A"> <PreferenceScreen android:title="TITLE B"> <PreferenceCategory android:title="category"> <ListPreference android:key="list" android:title="list" android:entries="@array/list_vals" android:entryValues="@array/list_vals1" android

How can I add my app's custom ringtones in res/raw folder to a ringtonepreference

a 夏天 提交于 2019-12-05 01:29:08
问题 I have this RingtonePreference (from Android Studio's default SettingsActivity): pref_notification.xml: <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <RingtonePreference android:dependency="notifications_alarm" android:key="notifications_alarm_ringtone" android:title="@string/pref_title_ringtone" android:ringtoneType="notification|all" android:defaultValue="content://settings/system/notification_sound" /> SettingsActivity.java: private void