android - Application crashes when setting the text of an EditText -


why application crash whenever try change text of edittext? have tried celc = (edittext) findviewbyid(r.id.cel) ; far = (edittext) findviewbyid(r.id.fa) ; ran = (edittext) findviewbyid(r.id.ran) ; kelvin = (edittext) findviewbyid(r.id.kev) ;
celc.addtextchangedlistener(new textwatcher() {

        @override         public void ontextchanged(charsequence s, int start, int before, int count) {             // 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 aftertextchanged(editable s) {             // todo auto-generated method stub             string value = s.tostring() ;             double c1 = double.parsedouble(value) ;              double f1 = (32+((9.0/5)*c1));             double r1 = f1+460 ;              double k1 = c1 + 273.0 ;              far.settext(f1+"");             ran.settext((r1 + ""));              kelvin.settext(k1+"");           }     }); doesn't work. 

  1. declare edittext in xml file
  2. find edittext in activity
  3. set text in edittext

and if check docs edittext, you'll find settext() method. takes in string , textview.buffertype. example:

edittext edittext =     (edittext)findviewbyid(r.id.edit_text); edittext.settext("google friend.", textview.buffertype.editable);  

or use +, string concatenation operator:

 ed = (edittext) findviewbyid (r.id.box);     int x = 10;     ed.settext(""+x); 

or

string.valueof(int): ed.settext(string.valueof(x)) 

Comments