Search code examples
androidvertical-scrollingandroid-textwatcher

Issue with textview Scrollable with textwatcher


I have a text view, and one edit text . When something is entered in the edit text it should calculate and display the results, here it will be more results, for an entry in edit text we will get around 8 to 10 outputs.

I have used,

android:scrollbars = "vertical"

and in activity,

output = (TextView) findViewById(R.id.textView);
output.setMovementMethod(new ScrollingMovementMethod());

and my logic,

public void onTextChanged(CharSequence s, int start,
                          int before, int count) {

    String subunit = categorySpinner.getSelectedItem().toString();
    if (subunit.equals("sad")) {
        Double ip = Double.valueOf(input.getText().toString());


        Double a = ip * 0.01;
        output.setText(String.valueOf(a) + "  " + "sdf"+"\n");

        Double b = ip * 31;
        output.setText(String.valueOf(b) + "  " + "Sdsf"+"\n");

        Double c = ip * 21;
        output.setText(String.valueOf(c) + "  " + "dfd"+"\n");

        Double f = ip * 2.47105;
        output.setText(String.valueOf(f) + "  " + "df"+"\n");

        ......
        ......
        ......

        Double z = ip * dfg;
        output.setText(String.valueOf(f) + "  " + "last output+"\n");
    }

}

But i am getting only the last output value in text view not all the output fields, anything missed here ?


Solution

  • Instead of setText() try append():

    output.append(yourText);
    

    append() will append the text to the existing buffer.