i have 'checklistitem' class has following properties:
private checkbox checkbox; private imagebutton notebutton; private textview vitalfield;
i have onclick listener
checkbox. problem is, when click on checkbox , onclick()
method gets called, how can figure out checklistitem checkbox part of?
whenever click on checkbox, want add checklistitem
checkbox part of array, onclick()
knows checkbox called it.
how can around this?
ok answer according "long discussion" had
let's assume want make - re usable - view of list , wrote separate xml layout file called list_item following:
<checkbox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/checkbox"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text_view"/>
so let's assume in activity or fragment or wherever want host view , have point out example , list view need in case again have little details app i'm going keep simple
assuming have vertical linear layout , want add these "rows" it, each row represents 1 of custom view
linearlayout layout = findviewbyid(r.id.layout); layoutinflater inflater = layoutinflater.from(this); // inflater responsible of creating instances of view view myview = inflater.inflate(r.layout.list_item, layout, false); // view objects view made in xml file checkbox checkbox = (checkbox) myview.findviewbyid(r.id.checkbox); textview textview = (textview) myview.findviewbyid(r.id.text_view); checkbox.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //if checkbox checked enable textview example // here have reference views created // weather want save them in class that's , app's logic } }); layout.addview((myview));
if list might exceed screen height may want wrap linear layout in scroll view.
btw: listview neat way automatically defining how want each row appear, , of course manages views , recycle them when of screen, wanted point out concept.
hope helps you
Comments
Post a Comment