android-preferences

How do I call a specific PreferenceFragment from a PreferenceActivity?

耗尽温柔 提交于 2019-12-29 06:05:52
问题 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

Launch Location Settings intent from preferences XML file

£可爱£侵袭症+ 提交于 2019-12-29 05:51:57
问题 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 to manage dividers in a PreferenceFragment?

旧街凉风 提交于 2019-12-28 02:56:28
问题 I started dealing with preferences in a PreferenceFragment . Here's what I have: I'm trying to: get rid of the dividers between items. I suppose this can be defined from styles, but I can't figure out how. I tried getting the preference ListView at runtime calling findViewById(android.R.id.list) , as I read somewhere, but it returns null. set new, full width dividers right on top of the headers, as seen here. For example in this case I want a full width divider right above "Statistiche", but

How to listen for preference changes within a PreferenceFragment?

半城伤御伤魂 提交于 2019-12-27 18:22:10
问题 As described here, I am subclassing PreferenceFragment and displaying it inside an Activity. That document explains how to listen for preference changes here, but only if you subclass PreferenceActivity. Since I'm not doing that, how do I listen for preference changes? I've tried implementing OnSharedPreferenceChangeListener in my PreferenceFragment but it does not seem to work ( onSharedPreferenceChanged never seems to get called). This is my code so far: SettingsActivity.java public class

How to listen for preference changes within a PreferenceFragment?

让人想犯罪 __ 提交于 2019-12-27 18:22:09
问题 As described here, I am subclassing PreferenceFragment and displaying it inside an Activity. That document explains how to listen for preference changes here, but only if you subclass PreferenceActivity. Since I'm not doing that, how do I listen for preference changes? I've tried implementing OnSharedPreferenceChangeListener in my PreferenceFragment but it does not seem to work ( onSharedPreferenceChanged never seems to get called). This is my code so far: SettingsActivity.java public class

android context and sharedpreferences

偶尔善良 提交于 2019-12-25 14:01:18
问题 I am trying to get context to run async sharedpreferences. Tried to get context with: public class MainActivity2 extends Activity implements OnClickListener { public MainActivity2(final Context context) { this.context = context; } private Context context; //....rest of class..... } But the app crashes when that it is included. But need something like that to get to sharedpreferences: class CreateUser extends AsyncTask<String, String, String> { // .....rest of .... @Override protected String

Android N: checking for DND state changed before updating checkbox preference

瘦欲@ 提交于 2019-12-25 09:03:04
问题 My app sets the ringer mode to silent but with Android N I get a java.lang.SecurityException: Not allowed to change Do Not Disturb state . I followed the steps from this post and the following code will open an activity which contains a toggle button for enabling the permission to change the ringer mode. This activity can be "backed" from without the enabling of the permission. Intent intent = new Intent( android.provider.Settings .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); startActivity

Problem with titles in PreferenceScreen (Android)

旧巷老猫 提交于 2019-12-25 08:59:38
问题 me again, working on some android live-wallpaper, again, I have a small weird problem. I create a first level of for my settings, everything is OKAY. But at some point, I needed some sub level and create a new as an item of the first one like in the following example: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/wallpaper_settings" android:key="wallpaper_settings"> <PreferenceScreen android:title=

setOnPreferenceChangeListener is called when assigning listener to preference in Android

心已入冬 提交于 2019-12-25 05:00:43
问题 In my preferences screen I set listeners to some preferences on onCreate() . But I've noticed the listener is called every time the preference is loaded (probably on the onCreate()). Is there a way to prevent this ? I want of course the listener to be called only when the preference value in the given key is changed. Thanks 回答1: You can achieve that this way. You need to register your listener in onResume and unregister in onPause . This way it won't get called when your activity is created

Why am I getting an error?: parameter t has incompatible upper bounds: Preference and Preference

限于喜欢 提交于 2019-12-25 01:17:42
问题 I can not solve the problem with the error: incompatible types: no unique maximal instance exists for type variable T with upper bounds com.velocat.cmap.Preference,androidx.preference.Preference Preference preference = findPreference("button"); ^ where T is a type-variable: T extends androidx.preference.Preference declared in method <T>findPreference(CharSequence) SettingsFragment.java import android.os.Bundle; import android.preference.Preference; import android.view.LayoutInflater; import