Programming Activities for Tablets
After you update your AndroidManifest
file, the next step is to begin coding the new activities that are unique to the tablet version of your app.
Creating the ReminderListAndEditorActivity
The tablet version of your app needs a new, main activity. One that works for phones doesn’t work with tablets because you want to retain that activity so that your app continues to work on phones. Create a ReminderListAndEditorActivity.java
file and add this code to it:
package com.dummies.android.taskreminder;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity; →4
public class ReminderListAndEditorActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list_and_editor); →10
}
}
Here’s how the code works:
→4 This line ensures you use the FragmentActivity
from the support library rather than the one built into Android 3.x and later. Otherwise your code doesn’t work on earlier versions of Android.
→10 The R.layout.reminder_list_and_editor
layout, which defines the layout for this activity doesn’t exist yet, but you create it later in this chapter.
Add the new activity to the AndroidManifest.xml
file beneath the ReminderEditActivity
that already exists for phones:
<activity android:name=”.ReminderListAndEditorActivity” android:label=”@string/edit_reminder_title”/>
Get Android Application Development For Dummies, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.