how to add customised layout to Arrayadapter?

前端 未结 5 1082
-上瘾入骨i
-上瘾入骨i 2020-12-09 06:35

I am trying to create a ListView with customized layout. each item in the listView should look like as shown in the item.xml posted be

5条回答
  •  清歌不尽
    2020-12-09 07:17

    ArrayAdapter accepts the second parameter as int something like android.R.layout.simple_list_item_1

    When not customizing getView method of ArrayAdapter then custom layout require one TextView with android:id="@android:id/text1" id and show value in one TextView.

    To run application with current code add android:id="@android:id/text1" for TextView in R.layout.listi_tems_layout layout.

    Because R.layout.listi_tems_layout layout contains other views also with TextView so create custom Adapter by extending ArrayAdapter class to access other views also.

    See following example:Custom ArrayAdapter for a ListView (Android)

提交回复
热议问题