KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 ListPreference) && (preference.getKey().equals("language"))){ ListPreference lp = (ListPreference)preference; CharSequence[] entries = { "English", "French" }; CharSequence[] entryValues = {"1" , "2"}; lp.setEntries(entries); lp.setDefaultValue("1"); lp.setEntryValues(entryValues); return true; } return false; } } and this is the settings.xml (preference) : <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="General Settings"> <CheckBoxPreference android:key="enabled" android:title="Application Status" android:summary="Enable or disable the application" /> <ListPreference android:key="language" android:title="Language" android:dialogTitle="Application language" android:summary="Select the Application language" /> </PreferenceCategory> </PreferenceScreen> I searched but found no result! An exception occurs every time I click on that list.
Tags (comma-separated)
Save Edits
Cancel