All we need to do is to create a new class which extends BaseAdapter, override the required methods, and add a constructor to initialise the adapter. However, in this example, we want to make the ImageView clickable, and we need to add listener to handle click events which cannot be done using SimpleAdapter, hence we need a custom adapter. In many cases we can get away with using SimpleAdapter as we did in the previous example, and simple add mappings to the constructor. The next thing that we need to do is to add a custom ListAdapter to make use of this layout. Additionally, we make the ImageView item clickable. We also give the LinearLayout an android:minHeight of “?android:attr/listPreferredItemHeight” so that we maintain consistency of the height of each ListView item. All we are really doing here is taking the TextView that comprises the stack layout for android.R.layout.simple_list_item_1, wrapping it in a horizontal LinearLayout, adding an ImageView, and giving the TextView an android:layout_weight of 1 to stretch to fill the available space.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |