如何从EclipseAndroid中的每个复选框中获取信息

如何从EclipseAndroid中的每个复选框中获取信息,android,eclipse,checkbox,gettext,Android,Eclipse,Checkbox,Gettext,我正在做一个关于计算购物清单上的钱的小程序。 我在说出我选择的复选框时遇到问题。 程序如下: 我的布局: 我的“activity_main.xml” 为每个复选框(购物项目)的ID-PRICE创建一个2D数组 单击按钮(计算所有选定列表) 或在选中或未选中的每个项目(复选框)上: CheckBox check = null; int total = 0; for(int i=0;i<id_price.length;i++){ check=(CheckBox)findViewBy

我正在做一个关于计算购物清单上的钱的小程序。 我在说出我选择的复选框时遇到问题。 程序如下:

我的布局:

我的“activity_main.xml”


为每个复选框(购物项目)的ID-PRICE创建一个2D数组

单击按钮(计算所有选定列表) 或在选中或未选中的每个项目(复选框)上:

CheckBox check = null;
int total = 0;
for(int i=0;i<id_price.length;i++){
    check=(CheckBox)findViewById(id_price[i][0]);
    if(check.isChecked()){
        total += id_price[i][1];//add item price to total
    }else{
        total -= id_price[i][1];//subtract item price from total
    }
}//for all check boxes
//now you have total ready for your next step ...
复选框check=null;
int-total=0;
对于(int i=0;i
CheckBox check = null;
int total = 0;
for(int i=0;i<id_price.length;i++){
    check=(CheckBox)findViewById(id_price[i][0]);
    if(check.isChecked()){
        total += id_price[i][1];//add item price to total
    }else{
        total -= id_price[i][1];//subtract item price from total
    }
}//for all check boxes
//now you have total ready for your next step ...