-
Notifications
You must be signed in to change notification settings - Fork 16
Part 1: Building the Android client
The Android Chat client should be able to send and receive messages from a chat room.
- Start Android Studio and create a new project called
MobosChatwith the base packagecom.mobos.android - Create a blank activity called
ChatActivity
The fragment will contain the layout for our chat application. Open the fragment_chat.xml (or the name you've given to out fragment layout) and define:
- A
ViewListthat will contain the chat messages - An
EditTextto write the message we want to send to the chat room - A
Buttonto send the message
Run the app and see you get the desired layout
In order to use RoboGuice for the dependency injection, we need to add it as a project dependency. Open the gradle.build file and add the RoboGuice dependency under the dependencies element
compile 'org.roboguice:roboguice:3.0b-experimental'
Make sure RoboGuice appears in your External Libraries
Our Android components will need to extend RoboGuice specific classes to have DI in place.
- Edit your
Fragmentand extend fromRoboFragment - Edit you
Activityand extend fromRoboFragmentActivity
In order to interact with the layout components, we'll be using the RoboGuice dependency injection
- Add a private field of type ListView and annotate it with @InjectView to get a reference of the declared list (ie:
@InjectView(R.id.messageList) private ListView mMessageList;) - Add a private field of type EditText and annotate it with @InjectView to get the reference of the declared text input.
- Add a private field of type Button and annotate it with @InjectView to get the reference of the declared button.