Android Socket iq Chat software chat bubble Coding steps Explained

Source: Internet
Author: User

Before we talked about the IQ chat software LAN chat test, today to everyone talk about bubble generation and coding, this is not a third-party thing, is their

Development, need to integrate layout and container to achieve, in fact, when you see the source, it will feel very simple, do not believe you follow me down to see

First of all, the idea of my programming, we are in an activity to dynamically generate a message list, the ListView is an essential container, this is one

Second, we can clearly know that "I" and friends of the bubble background is different, QQ's background is: "I" for the white bottom, friends "green Bottom", but this is the old version of, now the new version has a custom bubble, a lot of kinds, we do not introduce each, so we need to define two of the ListView Item to populate the ListView

Third, we put the layout file, the rest is to load the message list, today focus on the development of bubbles, and then about the bubble message list loading


first create an activity, add a ListView, because the source is uploaded, this is not posted code.


Define the message bubble layout file for "Me" and your friends separately:


This is a friend's message bubble layout, layout source please go to

source, attached database:http://download.csdn.net/detail/jspping/8067509

The main layout is a linear layout, with the main layout added an avatar ImageView, a send time TextView, nested a linear layout, adding a background image to the linear layout, that is, the green background bubble, in the linear layout added a friend message TextView, Show messages sent by friends


My bubbles:



Bubble real-time dynamic loading core code:

et_input= (EditText) Findviewbyid (r.id.et_input); Findviewbyid (R.id.ib_send). Setonclicklistener (New Onclicklistener () {public void OnClick (View v) {myaccount=moreactivity.me.getaccount (); ObjectOutputStream Oos;try { The Oos = new objectoutputstream//finds the thread through the account, resulting in OutputStream (Servermanager.getclientconserverthread (MyAccount). Getsocket (). Getoutputstream ());//Get input data and empty Edittextchatcontent=et_input.gettext (). toString (); et_input.settext ("");//Send Message iqmsg m=new iqmsg (); M.settype (iqmsgresult.com_mes); M.setsender (MyAccount); M.setsendernick ( MoreActivity.me.getNick ()); M.setsenderavatar (MoreActivity.me.getAvatar ()); M.setreceiver (Chataccount); M.setcontent (chatcontent); M.setsendtime (Iqtime.getimenos ()); Oos.writeobject (m);//Update chat content Updatechatview (new Messageentity (MoreActivity.me.getAvatar (), Chatcontent, Iqtime.getime (), false));} catch (IOException e) {e.printstacktrace ();}}});         Registered broadcast Intentfilter Myintentfilter = new Intentfilter ();  Myintentfilter.addaction ("Engineer.jsp.iq.Client.mes");      Br=new Mybroadcastreceiver (); Registerreceiver (BR, Myintentfilter); Manageactivity.addactiviy ("Messageactivity", this);} @Overridepublic void Finish () {unregisterreceiver (BR); Super.finish ();} Broadcast receiver public class Mybroadcastreceiver extends Broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent) {string[] mes = Intent.getstringarrayextra ("message");    LOG.I ("Messageactivity", "Data:" +mes); Update chat content Updatechatview (new messageentity (Integer.parseint (mes[2]), mes[3], mes[4], True));}} public void Updatechatview (Messageentity chatentity) {chatentitylist.add (chatentity); chatlistview= (ListView) Findviewbyid (R.id.lv_chat); Chatlistview.setadapter (new Messageadapter (This,chatentitylist));}

Do not know, please leave a message in this blog, the first time to see, the first time to answer! , thank you, engineer-jsp essays ~ ~

Android Socket iq Chat software chat bubble Coding steps Explained

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.