You can use a ScrollView to create a chat session. To start, try something like this:
ChatActivity.java :
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ChatActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
LinearLayout layout = (LinearLayout)findViewById(R.id.chatWindow);
//When you get a new message to display, you can add it at runtime like this:
TextView message1 = new TextView(this);
message1.setText("how are you");
layout.addView(message1);
//Add another message
TextView message2 = new TextView(this);
message1.setText("I'm fine");
layout.addView(message2);
}
}
Then create a chat.xml resource:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/chatWindow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" />
</ScrollView>
Later, you can use something like an AsyncTask to get better interaction with the user while updating the chat. An AsyncTask allows you to do things in the background while the user uses the UI.