在我的申请中我有
Edittext
s 和RadioGroup
两个RadioButton
s 和一个TextView
我需要在**三个EditText
的值之间进行一些计算,并在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());
}
});
这是我在文本视图中显示结果的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()函数中看到单选按钮卢比和百分比是否有卢比,计算正在运行,但百分比不是...... 我该如何解决这个问题?我似乎无法弄清楚这里的问题是什么......