Just as the title says. I implemented the Snackbar feature in my app, the first time the snackbar pops up it doesn't show the action, but on the second time it does. The code is below.
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) {
}
};
}
};
When you first time call your function your onClickListener is null.
Move:
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
}
};
Before if (result.isFailure()), or even to some kind of onCreate().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.