public override View GetView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder = null; Object item = this [position]; if (convertView == null || (convertView.Tag as ViewHolder).GetViewType() != GetItemViewType(position)) { viewHolder = new ViewHolder(); viewHolder.SetViewType(GetItemViewType(position)); switch (GetItemViewType(position)) { case TYPE_UNSUPPORTED: { convertView = new View(mInflater.Context); convertView.Tag = viewHolder; break; } case TYPE_MESSAGE: { convertView = mInflater.Inflate(Resource.Layout.SendBirdViewMessage, parent, false); viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView); viewHolder.SetView("img_op_icon", (ImageView)convertView.FindViewById(Resource.Id.img_op_icon)); convertView.Tag = viewHolder; break; } case TYPE_SYSTEM_MESSAGE: { convertView = mInflater.Inflate(Resource.Layout.SendBirdViewSystemMessage, parent, false); viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView); convertView.Tag = viewHolder; break; } case TYPE_BROADCAST_MESSAGE: { convertView = mInflater.Inflate(Resource.Layout.SendBirdViewSystemMessage, parent, false); viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView); convertView.Tag = viewHolder; break; } case TYPE_FILELINK: { TextView tv; convertView = mInflater.Inflate(Resource.Layout.SendBirdViewFileLink, parent, false); tv = convertView.FindViewById(Resource.Id.txt_sender_name) as TextView; viewHolder.SetView("txt_sender_name", tv); viewHolder.SetView("img_op_icon", convertView.FindViewById(Resource.Id.img_op_icon) as ImageView); viewHolder.SetView("img_file_container", convertView.FindViewById(Resource.Id.img_file_container)); viewHolder.SetView("image_container", convertView.FindViewById(Resource.Id.image_container)); viewHolder.SetView("img_thumbnail", convertView.FindViewById(Resource.Id.img_thumbnail)); viewHolder.SetView("txt_image_name", convertView.FindViewById(Resource.Id.txt_image_name)); viewHolder.SetView("txt_image_size", convertView.FindViewById(Resource.Id.txt_image_size)); viewHolder.SetView("file_container", convertView.FindViewById(Resource.Id.file_container)); viewHolder.SetView("txt_file_name", convertView.FindViewById(Resource.Id.txt_file_name)); viewHolder.SetView("txt_file_size", convertView.FindViewById(Resource.Id.txt_file_size)); convertView.Tag = viewHolder; break; } } } viewHolder = convertView.Tag as ViewHolder; switch (GetItemViewType(position)) { case TYPE_UNSUPPORTED: break; case TYPE_MESSAGE: { SendBird.Model.Message message = item as SendBird.Model.Message; viewHolder.GetView <ImageView> ("img_op_icon").Visibility = ViewStates.Gone; var messageView = viewHolder.GetView <TextView> ("message"); messageView.TextFormatted = Html.FromHtml("<font color='#824096'><b>" + message.GetSenderName() + "</b></font>: " + message.message); if (!messageView.HasOnClickListeners) { // To prevent mutiple click listners messageView.Click += (sender, e) => { var builder = new Android.App.AlertDialog.Builder(mContext); builder.SetTitle("SENDBIRD"); builder.SetMessage("Do you want to start 1:1 messaging with " + message.GetSenderName() + "?"); builder.SetPositiveButton("OK", (s, ev) => { Intent data = new Intent(); data.PutExtra("userIds", new string[] { message.GetSenderId() }); ((SendBirdChatActivity)mContext).SetResult(Android.App.Result.Ok, data); ((SendBirdChatActivity)mContext).mDoNotDisconnect = true; ((SendBirdChatActivity)mContext).Finish(); }); builder.SetNegativeButton("Cancel", (EventHandler <DialogClickEventArgs>)null); var dialog = builder.Create(); dialog.Show(); }; } break; } case TYPE_SYSTEM_MESSAGE: { SendBird.Model.SystemMessage systemMessage = item as SendBird.Model.SystemMessage; viewHolder.GetView <TextView> ("message").TextFormatted = Html.FromHtml(systemMessage.message); break; } case TYPE_BROADCAST_MESSAGE: { SendBird.Model.BroadcastMessage broadcastMessage = item as SendBird.Model.BroadcastMessage; viewHolder.GetView <TextView> ("message").TextFormatted = Html.FromHtml(broadcastMessage.message); break; } case TYPE_FILELINK: { FileLink fileLink = item as FileLink; if (fileLink.isOpMessage) { viewHolder.GetView <ImageView> ("img_op_icon").Visibility = ViewStates.Visible; viewHolder.GetView <TextView> ("txt_sender_name").TextFormatted = Html.FromHtml(" <font color='#824096'><b>" + fileLink.GetSenderName() + "</b></font>: "); } else { viewHolder.GetView <ImageView> ("img_op_icon").Visibility = ViewStates.Gone; viewHolder.GetView <TextView>("txt_sender_name").TextFormatted = Html.FromHtml("<font color='#824096'><b>" + fileLink.GetSenderName() + "</b></font>: "); } if (fileLink.fileInfo.type.ToLower().StartsWith("image")) { viewHolder.GetView("file_container").Visibility = ViewStates.Gone; viewHolder.GetView("image_container").Visibility = ViewStates.Visible; viewHolder.GetView <TextView>("txt_image_name").Text = fileLink.fileInfo.name; viewHolder.GetView <TextView>("txt_image_size").Text = fileLink.fileInfo.size.ToString(); if (fileLink.fileInfo.url != null && fileLink.fileInfo.url != "null") { DisplayUrlImage(viewHolder.GetView <ImageView> ("img_thumbnail"), fileLink.fileInfo.url); } } else { viewHolder.GetView("image_container").Visibility = ViewStates.Gone; viewHolder.GetView("file_container").Visibility = ViewStates.Visible; viewHolder.GetView <TextView>("txt_file_name").Text = fileLink.fileInfo.name; viewHolder.GetView <TextView>("txt_file_size").Text = "" + fileLink.fileInfo.size.ToString(); } viewHolder.GetView("txt_sender_name").Click += (sender, e) => { var builder = new Android.App.AlertDialog.Builder(mContext); builder.SetTitle("SENDBIRD"); builder.SetMessage("Do you want to start 1:1 messaging with " + fileLink.GetSenderName() + "?"); builder.SetPositiveButton("OK", (s, ev) => { Intent data = new Intent(); data.PutExtra("userIds", new string[] { fileLink.GetSenderId() }); ((SendBirdChatActivity)mContext).SetResult(Android.App.Result.Ok, data); ((SendBirdChatActivity)mContext).mDoNotDisconnect = true; ((SendBirdChatActivity)mContext).Finish(); }); builder.SetNegativeButton("Cancel", (EventHandler <DialogClickEventArgs>)null); var dialog = builder.Create(); dialog.Show(); }; break; } } return(convertView); }