如何在购买了用户币后减少用户币[关闭]


我需要帮助,每次当图像按钮被成功点击时,假设硬币足够,它会从用户的硬币减少他们购买的金额。您的帮助将是感激的。谢谢您的帮助。

我的店铺图片

    load30 = (ImageButton) findViewById(R.id.load30);
    load50 = (ImageButton) findViewById(R.id.load50);
    load100 = (ImageButton) findViewById(R.id.load100);
    load150 = (ImageButton) findViewById(R.id.load150);

    final SharedPreferences settings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);

    coins = settings.getInt("COINS", 0);
    tv_coins.setText("" + coins);


    load30.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Shop.this, Thirty.class));
        }

    });

解决方案:

//define a global variable

//could be other than 5 (you choose)
private final int REDUCED_AMOUNT = 5;


load30.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//lets say you reduce 5 coins on each click

if(coins>REDUCED_AMOUNT){

//get reduced coins
int reducedCoins = coins - REDUCED_AMOUNT; 

//write to shared preferences the new coins
SharedPreferences.Editor editor = settings.edit();
editor.putInt("COINS" , reducedCoins);
editor.commit();

//start another activity
startActivity(new Intent(Shop.this, Thirty.class));

}else{

//you don't have enough coins to buy

}
}

});

给TA打赏
共{{data.count}}人
人已打赏
未分类

我如何在Kofax Capture的现有批次中插入一组页面到所有现有文档中?

2022-9-10 22:11:23

未分类

如何利用rownum关键词在oracle中找到前5名不同的薪水?

2022-9-10 22:11:25

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索