Intent Code for the java File

Using the Package Explorer again, navigate to the src directory, open it, and right-click the android_programmers_guide.AndroidViews package, as shown in the following illustration.

4 . Edipje HaUurm I □ II 4=1 -iBäJ

hie fctlrl 'xiurte KeljLtur fdaviy-ite

■jeirtli Project

Kun Window Help

n * ^ - O - q, -

© &

-

£ © 4 1 . -

* <P '

E tH>e

uy jjjj^ |

p«ck*g<(.xpler £1 H.««wchyj N«v.g»tor

a

p'

< AivdroicfVitw;

Mil

t

Bp, Aniiraiil Libury

Go Unto

t}+ anifiuid jwugrimmeo guid

T-AndrttwMW»

Uptn in New Window

£> 45i«5

pi^n Type Hirrnrrhy

ft

G AndroidMiniftitJml

Shwrlri

aiusmuw»

Once again, you are going to add a new file to the folder. After you right-click the AndroidViews package, select New | File from the context menu. This file will hold all the code for the second Activity in this project. Name the file test.java. You should now have a nice, new (but empty) .java file. You just need to add a few lines of code to the file to make it usable:

package testPackage.test; import android.app.Activity; import android.os.Bundle; public class test extends Activity {

/** Called when the Activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.test); /** This is our Test Activity

All code goes below */

Notice that you call test.xml in the setContentView method, using the context RJayoutfesi. This line tells the new Activity to use the .xml file you created as the layout file for this "page."

0 0

Post a comment