android-preferences

PreferenceFragment.findPreference always returns NULL

夙愿已清 提交于 2019-11-29 03:57:40
I'm currently trying to make a settings menu, that will show a MultiSelectListPreference , to select multiple contacts from your contact list. At this moment, I'm receiving an NullPointerException , when i try to MultiSelectListPreference#setEntryValue(CharSequence[]) If I put the setEntries first, that one throws the same exception. I've put a breakpoint, to see step by step what happens. The variables are filled because they store Strings , they can contain a String "null", so I guess that it doesn't fail if there is no Display_Name available or so. I based the findPreference on the example

How do I call a specific PreferenceFragment from a PreferenceActivity?

人盡茶涼 提交于 2019-11-29 03:52:12
I have a PreferenceActivity with several fragments: R.xml.preferences: (shortened for better readability): <?xml version="1.0" encoding="utf-8"?> <preference-headers xmlns:android="http://schemas.android.com/apk/res/android"> <header android:fragment="fragments.Fragment1" android:id="@+id/fragment1" [...] /> <header android:fragment="fragments.Fragment2" android:id="@+id/fragment2" [...] /> [...] </preference-headers> SettingsActivity : public class SettingsActivity extends PreferenceActivity { @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml

Launch Location Settings intent from preferences XML file

安稳与你 提交于 2019-11-29 03:10:18
I want to launch System's Location Settings from an Intent . I know that programmatically it goes like this Intent viewIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(viewIntent); but I need to do it from the XML of a Preference . I try like this <Preference android:title="@string/pref_title" > <intent android:action="android.settings.ACTION_LOCATION_SOURCE_SETTINGS" /> </Preference> but it does not work, I always get an ActivityNotFoundException . How can I launch that System Location Settings from an XML Intent? Emil Adz You can create a:

Get preferences in AppWidget Provider

泪湿孤枕 提交于 2019-11-29 01:10:43
问题 I seem to be having trouble reading preferences from my AppWidgetProvider class. My code works in an Activity, but it does not in an AppWidgetProvider. Here is the code I am using to read back a boolean: SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); boolean autoreplyon = settings.getBoolean("autoreplyon", false); However, I get the "The method getSharedPreferences(String, int) is undefined for the type widget" error (widget is the name of my AppWidgetProvider class).

Setting UI preference Summary field to the value of the preference

旧时模样 提交于 2019-11-28 22:29:48
问题 New to Android, I have some code when the user changes a preference I update the Summary field in the UI preference to be the value they entered. However, when the preference activity is created I'd like to set the Summary fields to be the values in the corresponding preferences. Please advise. Thanks. public class MyPreferenceActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState

set custom font for text in PreferenceScreen

雨燕双飞 提交于 2019-11-28 21:53:38
My PreferenceActivity looks like: import android.os.Build; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.widget.TextView; public class Settings extends PreferenceActivity { @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.about); Typeface timesFont = Typeface.createFromAsset(getAssets(), "fonts/times.ttf"); TextView about_txt = (TextView) findViewById(R.id.about_txt); about_txt.setTypeface(timesFont);

Custom preference, targetSdkVersion=“11”: missing indent?

夙愿已清 提交于 2019-11-28 21:21:53
I have a couple of custom DialogPreference implementations floating around, such as this one : package apt.tutorial; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.preference.DialogPreference; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.TimePicker; public class TimePreference extends DialogPreference { private int lastHour=0; private int lastMinute=0; private TimePicker

How to change text color of preference category in Android?

蹲街弑〆低调 提交于 2019-11-28 19:11:59
The textColor attribute isn't working. Here's my XML: <PreferenceCategory android:title="Title" android:textColor="#00FF00"> Any ideas? use this customize PreferenceCategory class : public class MyPreferenceCategory extends PreferenceCategory { public MyPreferenceCategory(Context context) { super(context); } public MyPreferenceCategory(Context context, AttributeSet attrs) { super(context, attrs); } public MyPreferenceCategory(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onBindView(View view) { super.onBindView(view); TextView

How do I create custom preferences using android.support.v7.preference library?

北慕城南 提交于 2019-11-28 18:44:48
I want to support at least api 10, I want to be able to style my preferences nicely, I want to be able to have headers (or to show PreferenceScreen s). It seems that PreferenceActivity , not fully supported by AppCompat 's coloring, will not fit. So I'm trying to use AppCompatActivity and PreferenceFragmentCompat . public class Prefs extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, new PreferencesFragment())

How to fill ListPreference dynamically when onPreferenceClick is triggered?

十年热恋 提交于 2019-11-28 17:51:38
I have a preference activity that has a language as ListPreference which displays the available language list. I can fill the list when onCreate is called, but I want to fill the list when the user clicks on it. this is the java code : public class SettingsActivity extends PreferenceActivity implements OnPreferenceClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { addPreferencesFromResource(R.xml.settings); } catch (Exception e) { } } @Override public boolean onPreferenceClick(Preference preference) { if((preference instanceof