How to disable the EDIT-TEXT in android for entire activity -
how disable edit-text after clicking button entire activity?
here have 2 or more activities
example:
activity , b contains both edit_text , button
in activity entered values in edit_text , click ok button in coding part mentioned edittext1.setenabled(false)
. here edittext1
disabled
after switching activity b, , activity b activity a. edittext1
enabled
can 1 tell me how disable edittext1
entire activity
in advance
add = (button) findviewbyid(r.id.button1); add.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ed = (edittext) findviewbyid(r.id.edittext1); final string sq=ed.gettext().tostring(); if(sq.equals("a") || sq.equals("a")) { result++; display.settext(""+result);} } });
in activity a
read edittext1
i.e findviewbyid
, set edittext1.setenabled(false)
on onresume()
method of activity lifecycle.
on button
clicked use :
add = (button) findviewbyid(r.id.button1); add.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ed = (edittext) findviewbyid(r.id.edittext1); sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(activitya.this); editor ed = prefs.edit(); ed.putboolean(button_clicked, true); ed.commit(); edittext1.setenabled(false); final string sq=ed.gettext().tostring(); if(sq.equals("a") || sq.equals("a")) { result++; display.settext(""+result);} } });
on onresume
:
@override protected void onresume() { sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); boolena buttonclicked = prefs.getboolean(button_clicked, false); if(buttonclicked){ edittext edittext1 = (edittext) findviewbyid(r.id.edittext1); edittext1.setenabled(false); } }
Comments
Post a Comment