Home‎ > ‎android‎ > ‎Layout Enhanced‎ > ‎

Step By Step Implementation (Cont.2)

d. Locate codes to open the new screen.
A new screen may be initiated from clicking a button in previous screen, a clicking at menu item, or any other alternative. in this example we use the first one. Clicking a button in the first screen to open a new screen.

For this purpose, button onClick Method has been modified to do this. below is the code how we set the button:

Button btnEdu = (Button)findViewById(R.id.btnEdu);
btnEdu.setOnClickListener(new View.OnClickListener(){

public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(MyLayoutEnh.this,
startSubActivity(i, -1);


The code bold (ed) is for starting a new screen. firstly, instantiate aIntent class with parameters. one of its parameter is a class to handle the new screen ( EducationData.class ). and there is a command to begin starting the new screen. it is startSubActivity().

startSubActivity() is a method to start the screen, with first parameter is an intent, and the second is a result code request from the new screen, when the new screen is closed. On this example we pass -1 value as a second parameter denote that we have no request code resulted from this screen. In the next example we will use this.

e. Compile and Run the code

After previous step has been done, than we are ready to build it, and running when the build process is without error. transfer the .apk executable file to emulator, and run the code. below is two image after execution of this code. first image is first screen, the second image is after clicking the Education Button.

First Screen

Second Screen: A New Screen

Ok, good luck, and have a nice try!

Was this information helpfull ?