java - Get input from edittext using an anonymous class, android -
long story short trying make app convert celsius fahrenheit , back. want input edit text can use math, can't figure out, nor can button work right close it. want use internal anonymous class calculations , read in value, again no idea do. have idea start?
here have
package com.example.a4; import android.os.bundle; import android.app.activity; import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener; import android.text.editable; import android.text.textwatcher; import android.view.menu; import android.widget.button; import android.widget.edittext; public class mainactivity extends activity implements textwatcher { edittext mt=(edittext) findviewbyid(r.id.et1), mt2=(edittext) findviewbyid(r.id.et2); button bt = (button) findviewbyid(r.id.btn1); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //mt=(edittext) findviewbyid(r.id.et1); // mt2=(edittext) findviewbyid(r.id.et2); } onclicklistener oclbtnok = new onclicklistener() { @override public void onclick(dialoginterface arg0, int arg1) { // todo auto-generated method stub } }; /* buttonexit.setonclicklistener( new view.onclicklistener() { public void onclick(view v) { system.exit(0); } } );*/ @override public void aftertextchanged(editable s) { // todo auto-generated method stub int c = integer.parseint(s.tostring()); ftoc(c); } @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 } void ftoc(int c){ int f = ((9/5)*c) + 32; mt2.settext(f); } /* @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } */ }
you need move mt = (edittext)findviewbyid stuff oncreate. then, if want use anonymous classes, like:
mt.setonclicklistener(new onclicklistener() { public void onclick(view v) { ... } }); also, make sure you're using view.onclicklistener , not dialoginterface.onclicklistener (check imports).
Comments
Post a Comment