Chat application is very popular in mobile today. In this post i explain you how to create a simple mobile chat application like whatsapp, facebook messenger app. In this post i mainly focus on how to design chat application and how its work this is simple application i did not save data to server or any where but explain how you can get all that thing work and design. Before you get started you need to know about listview and how we can create a custom view and inflate view in listview. To learn about listview you follow my last post about Listview

Android Studio : Chat Application Download

Chat Application Android

Step 1. Create new Android application project in your Android Studio or in Eclipse.

Step 2. Now first we create a layout where we can display chat messages. First open your main xml file, I have activity_main.xml inside res folder. Open it and add Listview, Edittext and Button. I am using LinearLayout to make my design fit to every screen and adjust itself automatically.

Step 3. Now i need to create two more activity file which show message in left and right direction.

left.xml

right.xml

Now i create a round shape file for my Textview and save file inside drawable folder with this name textview.xml

Now our chat application design is ready to use. This is a very simple but you add more here according to your need.

Step 4. Now open your MainActivity.java  file and the following.

In above code i create a custom ArrayAdapter through this set data in my custom layout and also load specific layout.

I create sendChatMessage() method in above code in this i pass two thing first is side which tell who make this message and second msg text.

I also create a class to set direction and message and call inside my customArrrayAdapter as shown above.

ChatArrayAdapter.java

this is my main class which does all work you need to load data from service and set that data in listview.

If this post help you please like TrinityTuts page and share blog with others 🙂