0

正如标题所说。我在我的应用程序中实现了 Snackbar 功能,第一次弹出 Snackbar 时它不显示操作,但在第二次它会显示。代码如下。

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    @Override
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        if (result.isFailure()) {

            if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                mIsPremium = true;
                mAdView.setVisibility(View.GONE);
                removebutton.setText("PURCHASED");

                Snackbar.make(findViewById(R.id.container2), "Purchased", Snackbar.LENGTH_LONG)
                        .setAction("UNDO", mOnClickListener)
                        .setActionTextColor(Color.parseColor("#FFAB40"))
                        .setDuration(4000).show();
            }



        } else if (purchase.getSku().equals(ITEM_SKU)) {
            mIsPremium = true;
            mAdView.setVisibility(View.GONE);
            removebutton.setText("PURCHASED");
            Snackbar.make(findViewById(R.id.container2), "Ads have been removed", Snackbar.LENGTH_LONG)
                    .setAction("UNDO", mOnClickListener)
                    .setActionTextColor(Color.parseColor("#FFAB40"))
                    .setDuration(4000)
                    .show();
        }

        mOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        };

    }

};
4

1 回答 1

0

当您第一次调用您的函数时,您的 onClickListener 为空。

移动:

mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    };

在 if (result.isFailure()) 之前,甚至在某种 onCreate() 之前。

于 2015-11-03T11:42:18.670 回答