I have a link in my fragment, which shows " click to open dialog" ,upon clicking it, an alert dialog pops up, showing " do you want to change the view? " with yes and no notations. If I click no, nothing happens and dialog dismisses as expected. However, If I click yes, how do call a function to refresh my view and until my view is refreshed show a progress dialog? Here's my code so far, I dont know where to dismiss the progress dialog or make sure the view is refreshed, any clues? :
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Are you sure you want to refresh your view?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//refreshview here ?
ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "",
"Loading. Please wait...", true);
progressDialog.show();
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
Better to use AsyncTask
here and in onPostExecute(...)
dismiss your Progress Dialog
Take a look demos
Once you get data refresh your View
in onPostExecute(...)
//Progress Dialog Show logic here
Runnable r=new Runnable() {
@Override
public void run() {
//Dismiss the Dialog and refresh your Views
}
};
new Handler().postDelayed(r,10*1000);
This code is execute after 10 sec.