문제

I have some buttons in a ListView. When the user clicks on a button, a custom AlertDialog pops up. However, it takes some time for the AlertDialog to show because there are some images to load.

I want to make sure that the user can not click on the button again while the AlertDialog is loading, so I implemented a ProgressDialog that shows immediately onClick and dismisses as soon as the AlertDialog is there.

slotViewHolder.layout.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        ProgressDialog progressDialog = new ProgressDialog(context);
        progressDialog.setMessage("showing dialog...");
        progressDialog.show();

        loadDialogAndDoSomeAction();

        progressDialog.dismiss();
     }
});

The ProgressDialog still does not show. What am I doing wrong here? Are there better ways than this to prevent the user from doing something but wait?

Thanks in advance

도움이 되었습니까?

해결책 3

Ok I solved it by implementing an onShowListener on my progressDialog

slotViewHolder.layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    ProgressDialog progressDialog = new ProgressDialog(context);
    progressDialog.setMessage("showing dialog...");

    progressDialog.setOnShowListener(new OnShowListener() {

    @Override
    public void onShow(DialogInterface dialog) {
           loadDialogAndDoSomeAction();
    }

    progressDialog.show();
});     

I'm dismissing the ProgressDialog in Alertdialog.onShow() in loadDialogAndDoSomeAction()

다른 팁

in your custom adapter you can override

public boolean areAllItemsEnabled ();

just keep a boolean as member for your adapter, and when you click on it change it to false.

Dialog has an OnShowListener. You can implement this on your AlertDialog. Then dismiss your ProgressDialog there and make your Views clickable again or whatever you need.

myAlert.setOnShowListener(new OnShowListener()
{
    @Override
    public void onShow(DialogInterface Dialog)
    {
         progressDialog.dismiss();
         // here you can make things clickable, etc...
    }
}):

onShow Docs

You will want to make your ProgressDialog a member variable so you can access it in the onClick() and in onShow().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top