从用户购买成功后,我想启用"用户图库"上下文菜单中的项目。但是,我的代码什么也没做,我会感激一些帮助。谢谢!
这是我的onCreateOptionsMenu方法:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
if (purchaseSuccessful = false) {
menu.findItem(R.id.userGallery).setEnabled(false);
menu.findItem(R.id.purchase).setEnabled(true);
} else {
menu.findItem(R.id.userGallery).setEnabled(true);
menu.findItem(R.id.purchase).setEnabled(false);
}
return true;
}
这就是我设置我的" purchaseSuccessful"布尔值:
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
purchaseSuccessful = false;
return;
} else if (purchase.getSku().equals(ITEM_SKU)) {
consumeItem();
purchaseSuccessful = true;
invalidateOptionsMenu();
}
}
};