android对话框调用解除但不解雇

时间:2017-03-30 08:18:38

标签: android

我的Android应用编码有问题如下: 我使用dismiss()来隐藏对话框,但对话框并没有按预期消失。对话框保留在活动界面中,而实际调用dismiss()。

感觉就像被卡住或其他什么东西。硬件后退按钮也不起作用。应用只是卡在那里。 谁能帮我吗 提前谢谢。

示例图片 enter image description here 还有一些相关的代码。我使用MVP架构师。

@Override
    public void editAllNum(Context context, int num, List<ShopCar.GoodListBean> goodList) {
        Subscription s = Observable.just(num)
                .filter(integer -> goodList.size() != 0) //the goodList of size is never equal to 0. 
                .subscribeOn(Schedulers.io())
                .compose(TransformerUtil.showLoadingDialog(mView)) //call show dialog.
                .flatMap(new Func1<Integer, Observable<List<ShopCar.GoodListBean>>>() {
                    @Override
                    public Observable<List<ShopCar.GoodListBean>> call(Integer num) {
                        List<ShopCar.GoodListBean> list = new ArrayList<ShopCar.GoodListBean>();
                        for ( ShopCar.GoodListBean item : goodList ) {
                            if ( item.getRemainNum() != 0 ) { 
                                if ( item.getRemainNum() > num ) {
                                    
                                    if ( item.getLimit() != 0 ) {
                                        item = editNum(item, num); //editNum is not important
                                    } else {
                                        item.setNum(num);
                                    }
                                } else {
                                    
                                    if ( item.getLimit() != 0 ) {
                                        item = editNum(item, num);
                                    } else {
                                        item.setNum(item.getRemainNum());
                                    }
                                }
                            }
                            list.add(item);
                        }
                        return Observable.just(list);
                    }
                })
                .flatMap(new Func1<List<ShopCar.GoodListBean>, Observable<List<ShopCar.GoodListBean>>>() {
                    @Override
                    public Observable<List<ShopCar.GoodListBean>> call(List<ShopCar.GoodListBean> temp) {
                        return mPaymentImpl.updateGoodsNumAndQuery(context, temp); //operate databases update some data.
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<ShopCar.GoodListBean>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoadingDialog();
                    }
                    @Override
                    public void onNext(List<ShopCar.GoodListBean> list) {
                        mView.dismissLoadingDialog();// call dismiss dialog.
                        mView.setShopCarFromDB(list);
                    }
                });
        addSubscription(s);
    }

@Override
    public void showLoadingDialog() {
        if ( mLoadingDialog == null ) {
            mLoadingDialog = new LoadingDialog(getContext());
            LogUtils.e(" show loading dialog = " + mLoadingDialog);
        }
        mLoadingDialog.show();
    }

    @Override
    public void dismissLoadingDialog() {
        if ( mLoadingDialog != null ) {
            LogUtils.e(" dismiss loading dialog ");
            mLoadingDialog.dismiss();
        }
    }

Dialog的一些代码。

public class LoadingDialog extends Dialog {



    public LoadingDialog(Context context) {
        super(context, android.R.style.Theme_Translucent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.widget_loading_dialog);
        setCanceledOnTouchOutside(true);
        setCancelable(true);

    }
}

//XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/loading_dialog_bg"
        >

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            />

    </RelativeLayout>


</RelativeLayout>

最后,对不起我的英语。

1 个答案:

答案 0 :(得分:0)

首先检查mLoadingDialog的值是否为null。也许不知何故,价值为空。即。您在屏幕上看到的对话框可能不是mLoadingDialog。通过更改下面的函数,您在logcat中看到了什么?

Invoke