0

when adding the line of parsing the text to integer the app stops, and it works well without this line

final TextView secNumber= (TextView)findViewById(R.id.secNumber);
final EditText mainNumber=(EditText)findViewById(R.id.mainNumber);

mainNumber.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable S){
        secNumber.setText(Integer.parseInt(S.toString())*100);
    }

    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
            int arg3) {
        // TODO Auto-generated method stub

    }

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        // TODO Auto-generated method stub

    }
});
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
Mira
  • 195
  • 1
  • 3
  • 9

3 Answers3

1

Try this:

 secNumber.setText((Integer.parseInt(S.toString())*100).toString());
JiTHiN
  • 6,548
  • 5
  • 43
  • 69
0

You need to find out what's in S. Apparently, it's not parseable. Wrap the parseInt operation in a try catch block, or use a "TryParse", as illustrated here.

Community
  • 1
  • 1
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • Can you be more specific? I didn't really expect it to parse `S`, since what is in `S` is already not parseable. – Robert Harvey Aug 16 '12 at 22:29
  • the application stops again when using a "TryParse", as illustrated above. there was no difference – Mira Aug 16 '12 at 22:35
0

You are giving a Integer for secNumber.setText( Integer) and the function probably needs a String. Put a toString() at end.

Try something like that

Integer  pipi= Integer.parseInt(S.toString())*100);
secNumber.setText(pipi.toString());
kleopatra
  • 51,061
  • 28
  • 99
  • 211