How to add a progress bar to a PreferenceFragment? I have an async task running that will show some values in my preferences after completion. Therefore, when it executes a background process, I plan to show only the progress bar in the center. After completing the task, I plan to show all my preferences.
Here is what I still have.
Preferencefragment
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_account);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
new AsyncTask<Void,Void,Void>() {
String firstName, lastName, email;
@Override
protected void doInBackground() {
}
@Override
protected void onPostExecute() {
findPreference("first_name").setSummary(firstName);
findPreference("last_name").setSummary(lastName);
findPreference("email").setSummary(email);
}
}
}
pref_account.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:key="first_name"
android:title="@string/prompt_first_name"
android:summary="" />
<Preference android:key="last_name"
android:title="@string/prompt_last_name"
android:summary="" />
<Preference android:key="email"
android:title="@string/prompt_email"
android:summary=""
android:inputType="textEmailAddress" />
<Preference android:key="sign_out"
android:title="@string/action_sign_out" />
</PreferenceScreen>
My question is that this is a PreferenceFragment, and I am not overriding the onCreateView method, where and how to add a progress bar?
source
share