Multiple EditText in Android -
if have,say 20 edittext fields in program...and @ time want access 2 of them...then next 2...then next 2...and on....can using array of exittexts?? if yes can please provide me small example...
accessing each , every edittext separately can tedious job...i've tried implement in array...but every time giving me null pointer exception...all ids correctly provided...plus code works when provide each single edittext separately.
here code::
edittext e11,e12,e13,e21,e22,e23,e31,e32,e33,e41,e42,e43,e51,e52,e53,e61,e62,e63,e71,e72,e73,e81,e82,e83,e91,e92,e93,e101,e102,e103; edittext arr[]={e11,e12,e13,e21,e22,e23,e31,e32,e33,e41,e42,e43,e51,e52,e53,e61,e62,e63,e71,e72,e73,e81,e82,e83,e91,e92,e93,e101,e102,e103}; string ch1="",ch2="',ch3=""; for(c=0 9) { ch1=arr[(4*c)].gettext().tostring(); ch2=arr[(4*c)+1].gettext().tostring(); ch3=arr[(4*c)+2].gettext().tostring(); }
the loop giving me null pointer exception...even if set values edittexts hard coded.
you can use droidquery select edittext
s, , use each
method iterate on of them. can add textwatcher
or clicklistener
, or lot of other things en masse simple commands. example, select edittext
s, use:
$ droidquery = $.with(this).selectbytype("android.widget.edittext");
each edittext
can retrieved using view(int)
method. if want 2 @ time, can this:
edittext[] ets = new edittext[]{(edittext) droidquery.view(0), (edittext) droidquery.view(1)};//note: can size of current droidquery selection size() method. //todo eta.
the best way, however, each 1 follows:
$.with(this).selectbytype("android.widget.edittext").each(new function() { @override public void invoke($ droidquery, object... params) { edittext e = (edittext) droidquery.view(0); //todo manipulate e } });
you can add listeners on of them this:
$.with(this).selectbytype("android.widget.edittext").click(new function() { @override public void invoke($ droidquery, object... params) { edittext e = (edittext) droidquery.view(0); //todo handle e clicked } });
to add textwatcher, can this:
$.with(this).selectbytype("android.widget.edittext").change(new function() { @override public void invoke($ droidquery, object... params) { edittext e = (edittext) droidquery.view(0); //todo handle e after text has changed. } });
you can lot more library, sure read docs.
Comments
Post a Comment