如何将文本设置为整数,等于两个不同的变量一起添加

时间:2014-12-10 00:55:02

标签: java integer

这是我的代码:

public class TipCalculator extends Activity implements RadioGroup.OnCheckedChangeListener {

    EditText ba= null;
    TextView ta= null;
    TextView td= null;
    RadioButton t10= null;
    RadioButton t15= null;
    RadioButton t20= null;
    RadioGroup rg= null;
    DecimalFormat df=new DecimalFormat("$####.00");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tip_calculator);
        ba=(EditText)findViewById(R.id.bill_amount);
        ta=(TextView)findViewById(R.id.tip_amount);
        td=(EditText)findViewById(R.id.Total_Dollars);
        t10=(RadioButton)findViewById(R.id.ten);
        t15=(RadioButton)findViewById(R.id.fifteen);
        t20=(RadioButton)findViewById(R.id.twenty);
        rg=(RadioGroup)findViewById(R.id.tip_choices);
        rg.setOnCheckedChangeListener(this);
    }

    public void onCheckedChanged(RadioGroup rg, int i) {        
        if(i==t10.getId())
            ta.setText(df.format(Double.parseDouble(ba.getText().toString())*.10));
        if(i==t15.getId())
            ta.setText(df.format(Double.parseDouble(ba.getText().toString())*.15));
        if(i==t20.getId())
            ta.setText(df.format(Double.parseDouble(ba.getText().toString())*.20));

        if(i==t10.getId())
            td.setText(( ba.getText().toString()+(ta.getText().toString())));
        if(i==t15.getId())
            td.setText("$");
        if(i==t20.getId())
            td.setText ( df.format(Double.parseDouble(ta.getText().toString()) +  Double.parseDouble(ba.getText().toString())));
    }
}

我收到错误的代码部分是最后一部分。我试图设置变量" td"等于两个变量" ta"和" ba"但我得到一个错误或它连接变量的值而不是请帮忙! 提前谢谢!

1 个答案:

答案 0 :(得分:0)

td.setText(Double.toString(Double.valueOf(ba.getText().toString()) + Double.valueOf(ta.getText().toString())));