0

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();

2 Answers2

1

Better to use AsyncTask here and in onPostExecute(...) dismiss your Progress Dialog

Take a look demos

  1. Official Page
  2. Examples

Once you get data refresh your View in onPostExecute(...)

Edit:

 //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.

Community
  • 1
  • 1
M D
  • 47,665
  • 9
  • 93
  • 114
  • is there no easier way of doing this without asynctask based on my current code? –  Mar 04 '16 at 14:49
  • @JusticeBauer yes another way is by using `Handler`. – M D Mar 04 '16 at 14:50
  • can you show me how to use it with respect to my code? –  Mar 04 '16 at 14:51
  • @JusticeBauer But let me clear one thing is your new data coming from server to refresh view ? – M D Mar 04 '16 at 14:51
  • no its not, i want to refresh the view locally as in load it again upon clicking "yes" on the alert screen –  Mar 04 '16 at 14:54
  • @JusticeBauer wait let me provide the solution. – M D Mar 04 '16 at 14:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/105380/discussion-between-m-d-and-justice-bauer). – M D Mar 04 '16 at 14:57
  • @SOReadyToHelp any idea about my question here: https://stackoverflow.com/questions/57598276/how-do-i-pass-a-multi-part-body-parameter-for-rxjava2-androidnetworking-post-req ? –  Aug 25 '19 at 16:55
0

if you are not doing any operation on new thread no need for handler. Just call a method like:

private void updateView(ProgressDialog dialog){
   //UPDATE
   if(dialog != null){
     dialog.dismiss();
   } 
}
JannGabriel
  • 302
  • 5
  • 14