Is the controls in android is not publicly accessible within that activity? -
is controls in android not publicly accessible within activity (.java file)
here edittext field txt1 - want access in function public void clr()
how can it? possible or doing wrong?
this may basic qn. quite new java & android - though experienced in c#. pl help
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final textview res=(textview)findviewbyid(r.id.textview1); final edittext txt1 =(edittext) findviewbyid(r.id.edittext1); final edittext txt2 =(edittext) findviewbyid(r.id.edittext2); button btn = (button) findviewbyid(r.id.button1); btn.setonclicklistener(new onclicklistener() { public void onclick(view v) { // todo auto-generated method stub //some code here } }); button btnclr=(button) findviewbyid(r.id.button2); btnclr.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub txt1.settext(""); txt2.settext(""); res.settext(""); txt1.requestfocus(); } }); } public void clr(){ txt1.settext(""); txt2.settext(""); res.settext(""); txt1.requestfocus(); }
i know can pass txt1, txt2 arguments clr function. know whether above mentioned posible.
try following:
textview res; edittext txt1; edittext txt2; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); res=(textview)findviewbyid(r.id.textview1); txt1 =(edittext) findviewbyid(r.id.edittext1); txt2 =(edittext) findviewbyid(r.id.edittext2); button btn = (button) findviewbyid(r.id.button1); btn.setonclicklistener(new onclicklistener() { public void onclick(view v) { // todo auto-generated method stub //some code here } }); button btnclr=(button) findviewbyid(r.id.button2); btnclr.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub clr(); } }); } public void clr(){ txt1.settext(""); txt2.settext(""); res.settext(""); txt1.requestfocus(); }
Comments
Post a Comment