UIKit Android v3
UIKit Android
UIKit
Android
Version 3
Home
/
UIKit
/
Android
/
Customization

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: MessageListAdapter is used as an example in the codes below to show how to customize and add a new message type to the message list. You can replace MessageListAdapter with any other adapters used in UIKit to customize list items in fragments that use a list view.

  1. You need to inherit MessageListAdapter first and override onCreateViewHolder() and onBindViewHolder() methods like you would implement RecyclerView.Adapter in Android.
public class CustomMessageListAdapter extends MessageListAdapter {
    public CustomMessageListAdapter(GroupChannel channel) {
        super(channel);
    }

    @NonNull
    @Override
    public MessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 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
    public void onBindViewHolder(@NonNull MessageViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        final BaseMessage message = getItem(position);
        // TODO : Bind the custom `ViewHolder` to the `BaseMessage`.
    }

    @Override
    public int getItemViewType(int position) {
        BaseMessage message = getItem(position);
        // Create message type using a `BaseMessage` object.
        // If you want to use a `ViewHolder` that UIKit provides, you have to call `super.getItemViewType()`.
        // If you want to implement a custom message type, set the type as a number greater than 1,000.
        return super.getItemViewType(position);
   }
}
  1. Set the custom adapter in the onBeforeReady() method.
public class CustomChannelFragment extends ChannelFragment {
    @Override
    protected void onBeforeReady(@NonNull ReadyStatus status, @NonNull ChannelModule module, @NonNull ChannelViewModel viewModel) {
        super.onBeforeReady(status, module, viewModel);

        // TODO : Set the custom adapter in the `MessageListComponent`.
        // Use `viewModel` to bring channel data.
        final GroupChannel channel = viewModel.getChannel();
        if (channel != null) {
             module.getMessageListComponent().setAdapter(new CustomMessageListAdapter(channel));
        }
    }
}