Question

I have an Overlay extension which has 2 dialogs as private attributes - one Dialog and one ProgressDialog. After clicking on the Overlay in the MapView, the Dialog object appears. When the user clicks a button in the Dialog it disappears and the ProgressDialog is shown. Simultaneously a background task is started by notifying a running Service. When the task is done, a method (buildingLoaded) in the Overlay object is called to switch the View and to dismiss the ProgressDialog. The View is being switched, the code is being run (I checked with the debugger) but the ProgressDialog is not dismissed. I also tried hide() and cancel() methods, but nothing works. Can somebody help me? Android version is 2.2

Here is the code:

public class LODOverlay extends Overlay implements OnClickListener {



private Dialog overlayDialog;

private ProgressDialog progressDialog;

       ..............


@Override
public void onClick(View view) {

                   .......

        final Context ctx = view.getContext();
        this.progressDialog = new ProgressDialog(ctx);
        ListView lv = new ListView(ctx);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx, R.layout.layerlist, names);
        lv.setAdapter(adapter);
        final LODOverlay obj = this;
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
                String name = ((TextView) view).getText().toString();
        Intent getFloorIntent = new Intent(Map.RENDERER);
        getFloorIntent.putExtra("type", "onGetBuildingLayer");
        getFloorIntent.putExtra("id", name);
        view.getContext().sendBroadcast(getFloorIntent);
        overlayDialog.dismiss();

        obj.waitingForLayer = name;

        progressDialog.show(ctx, "Loading...", "Wait!!!");


            }
        });

    .......
}


public void buildingLoaded(String id) {
    if (null != this.progressDialog) {
        if (id.equals(this.waitingForLayer)) {
            this.progressDialog.hide();
            this.progressDialog.dismiss();

    ............

            Map.flipper.showNext();  // changes the view
        }
    }
}

}

Was it helpful?

Solution

Not sure if this is the cause of your issue, but the method you are calling on ProgressDialog is static, but you are calling it on an instance of the class. Here's the method definition:

public static ProgressDialog show (Context context, CharSequence title, CharSequence message)

As you can see, the method returns a ProgressDialog, it does not perform the show operation on your instance of the class. Update your code to use one of these:

progressDialog.setTitle("Loading...");
progressDialog.setMessage("Wait!!!");
progressDialog.show();

or

progressDialog = ProgressDialog.show(ctx, "Loading...", "Wait!!!");

OTHER TIPS

ProgressDialog.show(...) methods do in fact perform a show() on the dialog before returning it. Here is Android.jar source:

public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate,
        boolean cancelable, OnCancelListener cancelListener) {
    ProgressDialog dialog = new ProgressDialog(context);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(cancelListener);
    dialog.show();
    return dialog;
}

All the overloads of this method refer to this one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top