Skip to content

Commit 544fc98

Browse files
committed
Codelab improvements
1 parent befd789 commit 544fc98

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

codelabs/chat/README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
In this code lab you'll build a chat application for Android using Firebase and Android Studio.
44

5-
![Chat login](images/0_0.png)
6-
![Chat messages](images/0_1.png)
5+
<img alt="Chat login" src="images/0_0.png" height="600">
6+
<img alt="Chat messages" src="images/0_1.png" height="600">
77

88
What you'll learn:
99

@@ -271,7 +271,7 @@ Warning: if you end up making this `ChatMessage` an inner class of another class
271271

272272
With the layout for the message specified and their structure defined in a class, we need to make a space for them in the `main_activity.xml`
273273

274-
Add a ListView with `android:id="@android:id/list"`` above the LinearLayout:
274+
Add a ListView with `android:id="@android:id/list"` above the LinearLayout:
275275

276276
```xml
277277
<ListView
@@ -285,18 +285,12 @@ This is the container that all messages will be added to: one message_layout for
285285

286286
![activity_main.xml with ListView](images/5_4.png)
287287

288-
The `id` value is very important here, since Android's `ListActivity` uses it to find the `ListView`. So make sure to enter it exactly as specified: ``@android:id/list`.
289-
290-
Make the `MainActivity` class descend from `ListActivity`. This is a built-in Android base-class. By deriving from this, our activity will automatically have access to the ListView we added to the layout:
291-
292-
```java
293-
public class MainActivity extends ListActivity {
294-
```
288+
The `id` value is very important here, since we'll use it to look up this list before we populate it with items.
295289

296290
We're ready to start on our ListAdapter, which we'll base on the `FirebaseListAdapter` from the firebase-ui project we imported. `The FirebaseListAdapter` class adapts a Firebase collection so that it becomes usable in an Android `ListView`. First we'll add a member to our `MainActivity`:
297291

298292
```java
299-
public class MainActivity extends ListActivity {
293+
public class MainActivity extends AppCompatActivity {
300294
private Firebase mFirebaseRef;
301295
FirebaseListAdapter<ChatMessage> mListAdapter;
302296
```
@@ -306,6 +300,7 @@ public class MainActivity extends ListActivity {
306300
To make everything come together, we add this to the onCreate method of our MainActivity:
307301

308302
```java
303+
final ListView listView = (ListView) this.findViewById(android.R.id.list);
309304
mListAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class,
310305
android.R.layout.two_line_list_item, mFirebaseRef) {
311306
@Override
@@ -314,7 +309,7 @@ mListAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class,
314309
((TextView)v.findViewById(android.R.id.text2)).setText(model.getText());
315310
}
316311
};
317-
setListAdapter(mListAdapter);
312+
listView.setAdapter(mListAdapter);
318313
```
319314

320315
The FirebaseListAdapter maps the data from your Firebase database into the ListView that you added to the layout. It creates a new instance of your `two_line_list_item` for each `ChatMessage` and calls the `populateView` method. We override this method and put the name and text in the correct subviews.
@@ -462,7 +457,7 @@ Wrap-up
462457
463458
Congratulations! You've just built a fully functional multi-user chat application that uses Firebase to store the data and authentication users.
464459

465-
![Chat app with login](images/0_0.png)
460+
<img alt="Chat login" src="images/0_0.png" height="600">
466461

467462
As a reward for finishing the codelab you’ve earned a promo code! When you’re ready to put your Firebase app in production, you can use the promo code `androidcodelab49` for $49 off your first month of a paid Firebase plan. Just enter the code when you upgrade your Firebase.
468463

codelabs/chat/images/5_5.png

7.53 KB
Loading

codelabs/chat/images/5_6.png

12 KB
Loading

codelabs/chat/images/5_7.png

8.6 KB
Loading

0 commit comments

Comments
 (0)