Home > Enterprise >  Xamarin Firebase Chatapp Show Last Item in ListView
Xamarin Firebase Chatapp Show Last Item in ListView

Time:08-02

i try to create chat app with firebase. Everythings is done, but i just have one problem. Problem is i cant show coming or send new messages in listview. Message can be added listview but client should scroll manually to see new messages.

my problem is i cant use _lstchat.ScrollTo(), because i cant find value latest item in listview.

i try to use one more way;

i rotate my listview 180 and i can get good view but i cant sort my listview items or i cant add new item top on firebase database.

please help me i cant find a way.

This is my subchat code:

public async Task<ObservableCollection<Model.Chat>> subChat(string _roomKEY)
{
    var toUpdatePerson = (await fBclient
          .Child("ChatApp")
          .OnceAsync<Model.Room>()).Where(a => a.Object.Name == _roomKEY).FirstOrDefault();

    var data = fBclient.Child("ChatApp").Child(toUpdatePerson.Key).Child("Message")
                     .OrderByPriority()
                    .AsObservable<Model.Chat>()
                   .AsObservableCollection<Model.Chat>();
    return data;
}

CodePudding user response:

use FirstOrDefault() or LastOrDefault() to get the first or last item in the list

var newdata = await db.subChat(data.Name);
var first = newdata.FirstOrDefault();
_lstChat.BindingContext = newdata;

_lstChat.ScrollTo(first);
  • Related