Getting Fancy With Lists
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:id="@+id/check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout>
Arguably, the LinearLayout is superfluous, but we left it in to remind you that the rows could be more complicated than just a CheckBox â&#x20AC;&#x201C; you might have some ImageViews with icons depicting various bits of information about the row, for example. The ViewWrapper is similarly simple, just extracting the CheckBox out of the row View: class ViewWrapper { View base; CheckBox cb=null; ViewWrapper(View base) { this.base=base; } CheckBox getCheckBox() { if (cb==null) { cb=(CheckBox)base.findViewById(R.id.check); } }
return(cb);
}
And the result is what you would expect, visually:
102
This document is licensed for Cheng Po-wen's exclusive use by CommonsWare, LLC