Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中计算edittext的百分比值_Android_Android Edittext - Fatal编程技术网

在android中计算edittext的百分比值

在android中计算edittext的百分比值,android,android-edittext,Android,Android Edittext,我已经获得了代码,可以将多个edittext字段的值相加,并在一个字段中显示总数。现在,我需要将另外两个edittext字段的百分比计算与总值一起包括在内 editTexts = new EditText[] {monthly_rent_et, water_et,eb_et,sewage_et,maint_et,others_et,sec_deposit_et}; for (int i=0 ; i<editTexts.length ; i++) { editText

我已经获得了代码,可以将多个
edittext
字段的值相加,并在一个字段中显示总数。现在,我需要将另外两个
edittext
字段的百分比计算与总值一起包括在内

editTexts = new EditText[] {monthly_rent_et, water_et,eb_et,sewage_et,maint_et,others_et,sec_deposit_et};
    for (int i=0 ; i<editTexts.length ; i++) {
        editTexts[i].setOnFocusChangeListener(mFocusChangeListener);
    }

private View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        int total = 0;
        for (int i=0 ; i<editTexts.length-1 ; i++) {

            try {
                total += Integer.valueOf(editTexts[i].getText().toString());
            }
            catch(Exception e) {}
        }
        total_et.setText(total + "");

    }
};
EditText=新的EditText[]{每月租金、水、电子商务、污水、维护、其他、备用金等};

对于(int i=0;i假设
服务税和
惩罚税和
是新的
编辑文本
,不要将它们添加到数组中,而是手动对它们设置
焦点更改侦听器
,然后像这样尝试:

private View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
    float total = 0;
    for (int i=0 ; i<editTexts.length-1 ; i++) {
        try {
            total += Integer.valueOf(editTexts[i].getText().toString());
        }
        catch(Exception e) {}
    }

    try {
        float service_tax_perc = (Integer.valueOf(monthly_rent_et.getText().toString()) + Integer.valueOf(service_tax_et.getText().toString())) / 100;
        total += service_tax_perc;
    } catch (Exception e) {}

    try {
        float penalty_perc = (Integer.valueOf(monthly_rent_et.getText().toString()) + Integer.valueOf(penalty_et.getText().toString())) / 100;
        total += penalty_perc;
    } catch (Exception e) {}

    total_et.setText(total + "");
}};
private View.OnFocusChangeListener MFochsChangeListener=new View.OnFocusChangeListener(){
@凌驾
public void onFocusChange(视图v,布尔hasFocus){
浮动总数=0;

对于(int i=0;i您可以有一个编辑文本和一个文本视图..当用户输入时,计算并在文本视图中显示服务税百分比(使用一个通用函数)。所有值也是如此,总值有一个额外的文本视图..希望不要混淆。