如何根据选中的单选按钮更改TextView中的文本?

时间:2013-06-29 08:31:40

标签: android radio-button textwatcher

在我的申请中我有

  • 三个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()函数中看到单选按钮卢比和百分比是否有卢比,计算正在运行,但百分比不是...... 我该如何解决这个问题?我似乎无法弄清楚这里的问题是什么......

0 个答案:

没有答案