Add fragment into listview item

后端 未结 6 1021
-上瘾入骨i
-上瘾入骨i 2020-12-01 08:47

I want to have a fragment for each item in a listview, because I want to separate some logic out. I am using a view holder for each item. If the view doesn\'t exist, I creat

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 09:17

    I want to have a fragment for each item in a listview, because I want to separate some logic out.

    You can't use fragment as list item views because the API doesn't allow you - View and Fragment aren't even related so there's no way you can use it like that. Make custom views and use adapter getViewTypeCount and getView to use different list item behavior.

    Fragment are managed by Activity's FragmentManager or by other Fragments child FragmentManager; while list item views are managed by ListView & ListAdapter. You can use ListViews in Fragments, but not the other way around.

提交回复
热议问题