android - Get and Store text from looped checkboxes into a String -
i kinda new in android , java programming, , have question, wish me solve :)
i have program, fetch , loop data database , convert checkboxes, user must check checkboxes , hit submit button,, value(s) of checked checkboxes stored string[], send activity via intent.putextra..
so far, can fetch , loop data database, have no idea how store checked value (of checkboxes) string , sent activity via intent. can guys please me , should put code?
and here code :
private void fetchfromdatabase() { // todo auto-generated method stub mydb.open(); int totalgroup = mydb.counthowmanygroups(username); string groupid[] = mydb.fetchgroupid(username); string groupname[] = mydb.fetchgroupname(username); string flag[] = null; (int = 0; < totalgroup; i++) { listcheckbox = new checkbox(this); listcheckbox.settext(groupname[i]); listcheckbox.settag(groupid[i]); if (listcheckbox.ischecked()) { int x=0; flag[x]=listcheckbox.gettext().tostring(); x++; } layout.addview(listcheckbox); } mydb.close(); button bsubmit = new button(this); bsubmit.settext("submit"); layout.addview(bsubmit); bsubmit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub if (listcheckbox.ischecked()) { } } }); }
it depends of want store. want store id of selected checkboxes? override setoncheckedchangelistener
save it's id
on array (remember id 0 unless set it.)
do want save it's tag? override same method save tag instead.
here example of implementation of setoncheckedchangelistener
:
list<string> mytaglist = new arraylist<string>(); listcheckbox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked) mytaglist.add(buttonview.gettag()); else mytaglist.remove(buttonview.gettag()); } });
Comments
Post a Comment