第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Android 更新每次操作的價(jià)值總和

Android 更新每次操作的價(jià)值總和

BIG陽 2021-10-20 16:22:10
我正在做一個(gè)應(yīng)用程序,其中我的 textview 根據(jù)選中的復(fù)選框和單選按鈕立即更新自身。我有 3 個(gè)哈希圖來存儲(chǔ)每個(gè)項(xiàng)目的值:    hashMap.put("chkCheese", 2.50);    hashMap.put("chkPep", 3.50);    hashMap.put("chkChick", 2.00);    hashMap.put("chkBeef", 4.00);    hashMap.put("chkBlackOlives", 2.00);    hashMap.put("chkPine", 1.00);    hashMap.put("chkMushroom", 1.00);這是我的功能,用于顯示我的復(fù)選框更改時(shí)檢查的項(xiàng)目:    private void checkEnoughAndMakeDisabled (CheckBox checkBoxes []) {    int count = 0;    for (CheckBox cb:checkBoxes) {        cb.setEnabled(true);        if (cb.isChecked()) {            count++;            toppingsSelection.add(cb);        }    }    String text="";    for (CheckBox items: toppingsSelection) {        text = text + items.getText().toString() + ", ";    }    toppings.setText(text);    if (count >= 5) {        for (CheckBox cb:checkBoxes) {            if (!cb.isChecked()) {                cb.setEnabled(false);            }        }    }    toppingsSelection.clear();}在 onCreate() 中調(diào)用我的函數(shù):        //Display TOPPINGS text on each action made    final CompoundButton.OnCheckedChangeListener chgListener = new CompoundButton.OnCheckedChangeListener() {        @Override        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {            checkEnoughAndMakeDisabled(checkBox);        }    };    for (CheckBox tmpCheckBox: checkBox) {        tmpCheckBox.setOnCheckedChangeListener(chgListener);    }到目前為止,我只能顯示檢查項(xiàng)目的名稱。我試圖為我的 TextView priceSum 做類似的事情來顯示總和,但它不起作用。我還嘗試將計(jì)算和哈希圖標(biāo)記檢索放在 checkEnoughAndMakeDisabled 函數(shù)中,但它崩潰了。您認(rèn)為獲取哈希圖的值并進(jìn)行計(jì)算的最佳方法是什么?我的嘗試:       //Display PRICE text on each action made    price.setOnEditorActionListener(new TextView.OnEditorActionListener() {        @Override        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {            double cal=0.0;            for (int y=0;y<checkBox.length;y++) {                if (checkBox[y].isChecked()) {                    toppingsSelection.add(checkBox[y]);                }            }
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)