Live UIKit Android v1
Live UIKit Android
Live UIKit
Android
Version 1

Update or change an item in a list

Copy link

All UI in the form of lists in Sendbird UIKit are implemented using RecyclerView, which is a type of view that efficiently manages and displays large sets of data. In order to customize an item in a list, you need to customize the Adapter used in the RecyclerView. Adapters bind data sets of the list to the view that the list is displayed in.

Note: LiveEventListAdapter is used as am example in the codes below to show how to customize and add a new message type to the message list. You can replace LiveEventListAdapter with any other adapters used in UIKit to customize list items in fragments that use a list view.

  1. You need to inherit LiveEventListAdapter first and override onCreateViewHolder() and onBindViewHolder() methods like you would implement RecyclerView.Adapter in Android.
class CustomLiveEventListAdapter : LiveEventListAdapter() {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): LiveEventListAdapter.LiveEventListHolder {
        // TODO : Create a custom ViewHolder and return it.
        // You can customize a ViewHolder through the viewType parameter.
        // Call the super.onCreateViewHolder() method to go back to using the original view.
        return super.onCreateViewHolder(parent, viewType)
    }

    override fun onBindViewHolder(holder: LiveEventListAdapter.LiveEventListHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val liveEvent: LiveEvent = getItem(position)
        // TODO : Bind the custom ViewHolder to LiveEvent.
    }

    override fun getItemViewType(position: Int): Int {
        val liveEvent: LiveEvent = getItem(position)
        // Create liveEvent type using a liveEvent object.
        // If you want to use a ViewHolder that LiveUIKit provides, you have to call super.getItemViewType().
        return super.getItemViewType(position)
    }
}
  1. Set the custom adapter in the onCreate() method.
class CustomLiveEventListActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_custom_live_event_list)
        supportFragmentManager.commit {
            add(R.id.fcvMain,
                LiveEventListFragment.Builder()
                    .setLiveEventListAdapter(CustomLiveEventListAdapter()).build()
            )
        }
    }
}