I have a settings XML file, implemented in a PreferenceFragmentCompat class. In the XML file, I have a "android.support.v7.preference.EditTextPreference" in a "android.support.v7.preference.PreferenceScreen" like this :
android:key="#string/pref_key_code"
android:maxLines="1"
android:title="#string/pref_code_title"
When it was a simple "EditTextPreference" in a basic PreferenceScreen, this preference was working perfectly, but since I tried to change for v7.preference, it doesn't work anymore and I have this error when I click on it :
java.lang.IllegalStateException: Dialog view must contain an EditText with id #android:id/edit
at android.support.v7.preference.EditTextPreferenceDialogFragmentCompat.onBindDialogView(EditTextPreferenceDialogFragmentCompat.java:67)
at android.support.v7.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:148)
What do I have to do?
Related
I have a modified EditTextPreference with using SimpleSummaryProvider:
<NumberPreference
android:key="pref_key"
android:defaultValue="0"
android:title="Some title"
app:useSimpleSummaryProvider="true"/>
If I change this preference programmatically (for example in the onSharedPreferenceChanged event), then the summary in the graphical interface will not update. Is there any way to notify the Preference widget that it needs to read the value again and display it in the summary? Without manually assigning a specific value to the summary?
I am using PreferenceFragmentCompat and a modified EditTextPreference with a modified EditTextPreferenceDialogFragmentCompat.
I looked at the Android sources (EditTextPreferenceDialogFragmentCompat.java) - how the dialog for changing settings notifies EditTextPreference about a value change. Did as well and it worked :)
if (editTextPreference().callChangeListener(value)) {
editTextPreference().setText(value);
}
I'm working on a little app with a lot of modifiable preferences, most of them being SeekBarPreferences.
It happens that, since I'm quite not happy with Android default SeekBarPreferences, I'm using the very good MaterialSeekBarPreference library which unfortunately have not been updated for 2 years.
Here is an example of code used by this library:
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="#string/param_maxEvent"
android:title="Blahlblahblahblahblah"
android:summary="Blahlblahblahblahblah too"
android:defaultValue="2"
custom:msbp_minValue="0"
custom:msbp_maxValue="5"
custom:msbp_measurementUnit="events"
custom:msbp_interval="1"
custom:msbp_dialogEnabled="false"/>
As you can see, you can use the android:defaultValue xml attribute, and it works perfectly with the UI.
Since I need to load all these default values at app initialization, I use the PreferenceManager.setDefaultValues method:
public class App extends Application {
#Override public void onCreate() {
super.onCreate();
PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
}
}
This works fine with all default preferences (SwitchPreference, ListPreference, Preference), but unfortunately not with these custom SeekBarPreference.
Loading the preferences activity does not set up thoses default values either.
Is there any workaround for this problem ? Else, if I was up to edit the library, what should I change ?
I don't use the method PreferenceManager.getDefaultSharedPreferences(this, R.xml.preferences, true);. Instead, I use preference.setDefaultValue(object); in the Fragment.
I am new to Android development. I have developed a preferences activity in my Android Application. I wanted one Preference to open up a regular Activity. I created a preference object in my XML file and captured the onclick event in order to open the activity.
Code below:
<PreferenceCategory android:title="School">
<Preference
android:key="txtSchoolListPreference"
android:title="Select School"
android:clickable="true" />
</PreferenceCategory>
// Get selected school text box
Preference SelectedSchool =(Preference)findPreference("txtSchoolListPreference");
SelectedSchool.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
// Show the login intent
Intent i = new Intent(Settings.this,SchoolList.class);
i.putExtra(One.APP_ACTIVITY_NAME,One.APP_ACTIVITY_SETTINGS);
startActivityForResult(i, One.APP_ACTIVITY_SCHOOLLIST);
return true;
}
});
Everything works great but I would like to add the circle arrow-down icon to the preference but I don't know how.
Does anyone have any idea how I can add the circle arrow-down preference to the preference I have added to the page?
Getting the PreferenceActivity to show like the system's current theme is a bit more involved. Than just showing the Android vanilla arrow. You'll have to create a subclass of DialogPreference (code on github). Use the code from EditTextPreference (code on github) as a template on how to create your subclass. As it appears you'll be starting another Activity this will be easier than creating one that displays another dialog (was not that easy in my experience).
To include your preference in the Preference Resource xml file use the fully qualified name with a leading capital letter. For example class Foo in package com.stackoverflow would appear as <Com.stackoverflow.Foo>. This is similar to how custom view widgets are used in xml layouts.
The reason you have to do it this way is the arrow is an internal resource so we have to go to some extremes to use the internal resource.
I am tryig to write an Android Honeycomb application and I am having trouble subclassing Preference: http://developer.android.com/reference/android/preference/Preference.html
I want to make a similar layout with title and summary but also a progress bar.
I have created the layout and added the custom preference class but I can't seem to get hold of the instance of it to set the values of the items in it.
It seems that the preference key doesn't work for the custom class.
Here is my preference definition compared to the standard preference class:
<Preference
android:key="int_free_storage"
android:title="Free Space"
android:summary="free storage value here"/>
<com.hamid.storageether.SpacePreference
android:key="int_space_test"
android:title="Test"
android:summary="This is my custom preference"/>
My my preference subclass then sets my XML layout as it's layout resource in its constructor
setLayoutResource(R.layout.space_pref_layout);
it also overrides the setTitle and setSummary methods....
In my main PreferenceActivity I try to get hold of my Preference by it's key but no luck it seems, since the preference never gets updated:
// These Two work
Preference intTotal = (Preference)findPreference("int_total_storage");
Preference intFree = (Preference)findPreference("int_free_storage");
intTotal.setSummary("Standard Preference Summary 1");
intFree.setSummary("Standard Preference Summary 2");
// My subclass doesn't - It just displays the default text defined in the layout xml.
SpacePreference intTest = (SpacePreference)findPreference("int_test_space");
intTest.setTitle("Testtttyyy");
intTest.setSummary("Test Summary");
Could someone please point me towards where I may be going wrong?
Is this code copied straight from the program or retyped? If copied, then your key is "int_space_test" in XML and "int_test_space" in code. It should be throwing a null pointer exception on the next line where you use intTest if that's the case.
I would like to use EditTextPreference to show 2 input fields instead of 1. For instance, a username and password field should be shown. I don't want to use a dialog for each one. How can this be done? In the WiFi settings there is one that does this, when you want connect to a protected network, a dialog shows to set a password for the credential storage with 2 fields.
You can use a DialogPreference and create your own layout for the input fields you require.
DialogPreference is abstract so you'll need to create your own subclass of it, adding an implementation of onDialogClosed() to save the values from the dialog as Preferences.
You can still reference your own class in a Preferences XML file by using the class as the XML tag. For example:
<com.yourdomain.YourDialogPreference
android:title="Title"
android:summary="Summary"
android:key="dialog_preference"/>