java - Android: Add view into another while having a click listener on the parent -
i trying achieve following hierarchy: gridview -> every item view (let's call 'container') contains background, imageview , checkbox.
if user clicks on container, doesn't matter where, whether on checkbox, image, or background, checkbox should change checked state.
right have following layout it:
<!-- main layout --> <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <button android:id="@+id/selectbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="select" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:minwidth="200dp" /> <gridview android:id="@+id/imagegridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numcolumns="auto_fit" android:verticalspacing="10dp" android:horizontalspacing="10dp" android:columnwidth="90dp" android:stretchmode="columnwidth" android:gravity="center" android:layout_above="@id/selectbtn" /> </relativelayout> <!-- gallery item layout - every grid item inflated --> <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <imageview android:id="@+id/thumbimage" android:layout_width="110dp" android:layout_height="110dp" android:background="#999999" android:layout_centerinparent="true" android:contentdescription="image thumb"/> <checkbox android:id="@+id/itemcheckbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_alignparenttop="true" /> </relativelayout>
after want able retrieve checked containers.
i don't know how create layout. tho layout appears alright now, there no 'container' react click listener. can make checkbox react click, of course not user-friendly. how add wrapper container around these views serve clicking? lot!
ah, never mind... relativelayout extends view , viewgroup, can use like:
relativelayout container = (relativelayout) holder.imageview.getparent(); container.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.d("test", "clicked"); relativelayout cont = (relativelayout) v; checkbox cb = (checkbox) cont.getchildat(1); if(cb.ischecked()) cb.setchecked(false); else cb.setchecked(true); } });
Comments
Post a Comment