android - Update ListView everytime the Data changes -
i'm building chat using php , java, i'm getting data chat using json file, , inserting data calling php file inserts new message database.
i'm listing messages in listview
, , trying update listview
everytime new message sent, code working, automatically update listview
when send new message.
i have click @ chat room again see listview
updated. update listview
both users, receiver , sender.
i tried update adapter using: notifydatasetchanged();
didn't work.
how can that?
code:
my adapter:
@override protected void onpostexecute(void result) { super.onpostexecute(result); // dismiss progress dialog if (pdialog.isshowing()) pdialog.dismiss(); /** * updating parsed json data listview * */ adapter = new costumeadapter( chatroomactivity.this, contactlist, r.layout.chat_row, new string[]{ tag_message, tag_conversation }, new int[]{ r.id.name, r.id.conversationid }); setlistadapter(adapter); }
class
public view getview(int position, view convertview, viewgroup parent){ view v = super.getview(position, convertview, parent); textview text = (textview) v.gettag(); if(text == null){ text = (textview) v.findviewbyid(r.id.name); v.settag(text); } string pos = (string) ((map)getitem(position)).get(tag_position); text.setbackgroundresource(pos.equals("left") ? r.drawable.bubble_green : r.drawable.bubble_yellow); conversationid = (textview)v.findviewbyid(r.id.conversationid); send.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string getmessage = txtmessage.gettext().tostring(); string getconversationid = conversationid.gettext().tostring(); sendmessage mtask = new sendmessage(); mtask.execute(sessionid,getmessage,getconversationid); adapter.notifydatasetchanged(); } }); return v; }
thanks.
you have use adapter.notifydatasetchanged();
. have create listener
, make listview
implements it. listener
put adapter.notifydatasetchanged();
. call method when each device receives information
Comments
Post a Comment