I have the following ListPreference in a PreferenceActivity that I wish to populate with phone numbers that I retrieve from a web service. How do I go about succeeding in doing this ?
<PreferenceCategory
android:title="@string/category_shownumber">
<ListPreference
android:title="@string/shownumber_header"
android:summary="@string/shownumber_summary"
android:key="shownumber_list"
android:defaultValue="@string/shownumber_default"
android:entries="@array/listArray"
android:entryValues="@array/listValues" />
</PreferenceCategory>
I wish for my android:entries to be from the string array returned by doInBackground in this class :
private class PullNumbersTask extends AsyncTask<Void, Void, String[]>
{
private Context ctx;
public PullNumbersTask(Context context)
{
super();
this.ctx=context;
}
private ProgressDialog Dialog = new ProgressDialog(getParent());
protected void onPreExecute()
{
Dialog.setMessage("Fetching numbers..");
Dialog.show();
}
@Override
protected String[] doInBackground(Void... arg0) {
return (userControl.GetNumbers());
}
protected void onPostExecute(String[] result)
{
// Do stuff with my array
}
Any suggestions?
How about simply calling this in your onPostExecute
listPref.setEntries(result);
(obviously you'd need a reference to the ListPreference object)
To actually get a hold on the ListPreference object, you would do
ListPreference listPref = (ListPreference) findPreference("shownumber_list");
the call to addPreferencesFromResource(R.xml.preferences);
must have been done before that (most likely in the onCreate())