在我的应用程序中,我有
- 三秒
Edittext
和_ - 一个
RadioGroup
有 两个RadioButton
s和一个TextView
我需要在 **three EditText
s 的值之间进行一些计算并将结果显示在TextView
.... 我已经TextWatcher
为前两个EditText
设置了结果,以便以这种方式同时显示结果..
discount.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
// TODO Auto-generated method stub
display.setText(calFinance());
}
});
assetCost.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
// TODO Auto-generated method stub
display.setText(calFinance());
}
});
这是我在 textview 中显示结果的 cal 财务方法:
protected CharSequence calFinance() {
// TODO Auto-generated method stub
int c1,c2,c3,c4 = 0;
if((assetCost.getText().toString() != "") && (assetCost.getText().length() > 0)){
c1=Integer.parseInt(assetCost.getText().toString());
as_Asset_Cost=assetCost.getText().toString();
}else{
c1=0;
}
if(discount.getText().toString() != "" && discount.getText().length()>0){
c3 = Integer.parseInt(discount.getText().toString());
as_Discount=discount.getText().toString();
}else{
c3=0;
}
if(rupees.isChecked()){
if(marginalAmt.getText().toString() !="" && marginalAmt.getText().length() > 0){
c2=Integer.parseInt(marginalAmt.getText().toString());
as_Margin_Amount=marginalAmt.getText().toString();
c4 =(c1 - c2 -c3);
ma_Finance_Amount = display.getText().toString();
}else{
marginalAmt.setError("ERROR");
}
}else if(percent.isChecked()){
if((marginalAmt.getText().toString() !="") && (marginalAmt.getText().length() > 0) && (marginalAmt.getText().length() <= 2)){
c2=Integer.parseInt(marginalAmt.getText().toString());
as_Margin_Amount=marginalAmt.getText().toString();
c4 = (c1*(1-(c2)/100))-c3;
ma_Finance_Amount = display.getText().toString();
} else{
marginalAmt.setError("ERROR");
}
} else{
c2 = 0;
c4 = c1-c3;
ma_Finance_Amount = display.getText().toString();
}
//return as_Asset_Cost;
return String.valueOf(c4);
}
现在根据选择的单选按钮,textview中的结果应该改变..正如你在calfinance()函数中看到的那样,单选按钮卢比和百分比对于卢比来说是有效的,但是对于百分比它不是......如何我要解决这个问题吗??我似乎无法弄清楚这里的问题是什么......