android - Referencing checkBoxes -
the program being worked upon using api collect information required, making activity dynamic. due dynamic nature presentation layout, x.xml being used specify styling of elements. layout contains title, information , checkbox. problem having can refer last checkbox of layout since of them have same id specified in layout. there way can refer/loop through checkboxes in layout ? not last checkbox element using type of layout ?
the layout file
contains following:
<textview> <textview> <checkbox android:id> the java class following code refer it:
checkbox check =(checkbox)findviewbyid(r.id.checkbox); check.setonclicklistener .... and since working apis using asynctask's onpostexecute fill in activity.
this easy droidquery library. in activity, call this:
$.with(this).selectbytype(checkbox.class.getname()).each(new function() { @override public void invoke($ droidquery, object... params) { checkbox cb = (checkbox) droidquery.view(0); //todo: manipulate each checkbox here. } }); to add click listener, add chain call click (either instead, or @ end):
by iteself
$.with(this).selectbytype(checkbox.class.getname()).click(new function() { @override public void invoke($ droidquery, object... params) { checkbox cb = (checkbox) droidquery.view(0); //todo: handle clicked checkbox } }); chained call
$.with(this).selectbytype(checkbox.class.getname()).each(new function() { @override public void invoke($ droidquery, object... params) { checkbox cb = (checkbox) droidquery.view(0); //todo: manipulate each checkbox here. } }).click(new function() { @override public void invoke($ droidquery, object... params) { checkbox cb = (checkbox) droidquery.view(0); //todo: handle clicked checkbox } });
Comments
Post a Comment