Android Programming Tutorials

(Romina) #1
Getting More Active

package apt.tutorial;

import android.app.Activity;
import android.os.Bundle;

public class DetailForm extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
}
}

This is just a stub activity, except it has the setContentView() line


commented out. That is because we do not want to use main.xml, as that is


the layout for LunchList. Since we do not have another layout ready yet, we


can just comment out the line. As we will see, this is perfectly legal, but it


means the activity will have no UI.


Step #2: Launch the Stub Activity on List Click................................


Now, we need to arrange to display this activity when the user clicks on a


LunchList list item, instead of flipping to the original detail form tab in


LunchList.


First, we need to add DetailForm to the AndroidManifest.xml file, so it is


recognized by the system as being an available activity. Change the


manifest to look like the following:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name">
<activity android:name=".LunchList"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailForm">
</activity>

110
Free download pdf