I have a Loader class which just creates a ProgressDialog and show it.
Now, I have an Activity which I need to use the loader in it.
That activity loads items dynamically into a ListView member. I want to use the Loader class and show the ProgressDialog while loading the ListView.
I thought about loading the listview in a seperate class and send it to the activity, but I didn’t find how to send “ListView” to another intent.
I’ve also considered making the ListView object a static object, so I would access it from another class, but I prefer not to (Static member is not recommended).
Any other ideas ?
package android.example;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
public class Loader extends AsyncTask<Void, Void, Void> {
private ProgressDialog dialog;
public Loader(Activity activity) {
dialog = new ProgressDialog(activity);
}
@Override
protected void onPreExecute() {
dialog.setMessage("Loading");
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
return null;
}
@Override
protected void onPostExecute(Void res) {
dialog.dismiss();
}
}
what matters in a
ListViewis after all it’s data. you can just send the data or set the already used data aspublic staticand then reuse yourAdapter.I think this would be much easier and your code will be clean.