In my application i have
- three
Edittext
s and - one
RadioGroup
with twoRadioButton
s and aTextView
I need to do some calculation between the values of the **three EditText
s and display the result in the TextView
....
I have put TextWatcher
for the first two EditText
so that the result is displayed simultaneously in this way..
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());
}
});
and this is the cal finance method where i am displaying the result in textview:
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);
}
now according to what radio button is selected the result in the textview should change.. as u can see in the calfinance() function the radio buttons rupees and percent is there for rupees the calculation is working but for percent its not... how do i solve this issue?? I cant seem to figure out what the problem is here...