android - How to update item of Model Class in ArrayList that goes into RecyclerAdapter -
i have model class store user chats info
public class userchat { private string ownerid; private string ownername; private string receivername; private string message; private long time; private long oldtime; private string seentick; public userchat() { } public userchat(string ownerid, string ownername, string receivername, string message, long time, long oldtime, string seentick) { this.ownerid = ownerid; this.ownername = ownername; this.receivername = receivername; this.message = message; this.time = time; this.oldtime = oldtime; this.seentick = seentick; } public string getmessage() {return message;} public void setmessage(string message) { this.message = message; }....
initially, retrieving data onchildevenlistener
, add arraylist.
userchatlist = new arraylist<userchat>(); chatrecycleradapter = new chatrecycleradapter(userchatlist); mchatlist.setlayoutmanager(mlayoutmanager); mchatlist.setadapter(chatrecycleradapter); mchatroom.child(useruid).child(useruid + "_" + receiver_uid).child("chatlist").addchildeventlistener(new childeventlistener() { @override public void onchildadded(datasnapshot datasnapshot, string s) { log.d(tag, "childadded"); userchats = new userchat(); if(datasnapshot.haschild("message")){ string message = datasnapshot.child("message").getvalue().tostring(); log.d(tag, "messageoo " + message); userchats.setmessage(message); } if(datasnapshot.haschild("ownerid")){ string ownerid = datasnapshot.child("ownerid").getvalue().tostring(); log.d(tag, "owneridoo " + ownerid); userchats.setownerid(ownerid); } if(datasnapshot.haschild("ownername")){ string ownername = datasnapshot.child("ownername").getvalue().tostring(); log.d(tag, "ownernameoo " + ownername); userchats.setownername(ownername); } if(datasnapshot.haschild("receivername")){ string receivername = datasnapshot.child("receivername").getvalue().tostring(); log.d(tag, "receivernameoo " + receivername); userchats.setreceivername(receivername); } if(datasnapshot.haschild("seentick")){ string seentick = datasnapshot.child("seentick").getvalue().tostring(); log.d(tag, "seentickoo " + seentick); userchats.setseentick(seentick); } if(datasnapshot.haschild("oldtime")){ long oldtime = (long) datasnapshot.child("oldtime").getvalue(); log.d(tag, "oldtimeoo " + oldtime); userchats.setoldtime(oldtime); } if(datasnapshot.haschild("time")){ long time = (long) datasnapshot.child("time").getvalue(); log.d(tag, "timeoo " + time); userchats.settime(time); } userchatlist.add(userchats); chatrecycleradapter.notifydatasetchanged(); }
however, want update arraylist items whenever there change in item named "seentick" triggers onchildchanged.
@override public void onchildchanged(datasnapshot datasnapshot, string s) { log.d(tag, "onchildchanged"); if(userchatlist!=null){ if(datasnapshot.haschild("seentick")){ string seentick = datasnapshot.child("seentick").getvalue().tostring(); log.d(tag, "seentickooxx " + seentick); chatrecycleradapter.notifydatasetchanged(); //how update userchatlist??? } } }
how can update item "seentick" in arraylist, not clear()
, add()
whole list again??
Comments
Post a Comment