Friday, 24 January 2020

Xamarin Android how to show list if user start typing with @ special character like whatsapp tagging features?

I want to show the user list when the user starts typing with @ special character like tagging features in WhatsApp.

I use a regular expression but it works for only the first word not working for second words, like "Hello @abc and @xyz."

below is my code.

if (searchtext.ToString().Contains("@"))
{
   Regex regex = new Regex("@([a-zA-Z])+");
   MatchCollection matches = regex.Matches(searchtext.ToString());
   if (matches != null && matches.Count != 0)
    {
       string temptext = matches[matches.Count - 1].ToString().Substring(1);
       searchUserList = userList.Where(s=>s.userName.ToLower().StartsWith(temptext.ToString().ToLower())).ToList();

       _usersListAdapter = new TagUsersListAdapter(this.Activity, searchUserList, this);
       _lstViewUsers.SetAdapter(_usersListAdapter);

       _lstViewUsers.Visibility = ViewStates.Visible;
    }
    else
    {
        _lstViewUsers.Visibility = ViewStates.Visible;
    }

}
else
{
   _lstViewUsers.Visibility = ViewStates.Gone;

   _usersListAdapter = new TagUsersListAdapter(this.Activity, userList, this);
   _lstViewUsers.SetAdapter(_usersListAdapter);
}


from Xamarin Android how to show list if user start typing with @ special character like whatsapp tagging features?

No comments:

Post a Comment