Android Viewsjava

The last step to create this Activity is to edit the AndroidViews.java. If you want to call the testEditText Activity from the main AndroidViews Activity, you must add code to the AndroidViews.java. Compare the following code with that in your current AndroidViews.java. Add the needed code to complete your file.

package android_programmers_guide.AndroidViews;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.content.Intent;

public class AndroidViews extends Activity {

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

@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu);

menu.

. add

10,

0,

"AutoComplete"

menu.

. add

10,

1,

"Button");

menu.

. add

10,

2,

"CheckBox");

menu.

. add

10,

3,

"EditText");

menu.

. add

10,

4,

"RadioGroup");

menu.

. add

0,

5,

"Spinner");

return true;

@Override public boolean onOptionsItemSelected(Menu.Item item){ switch (item.getId()) { case 0:

showAutoComplete(); return true; case 1:

showButton(); return true; case 2:

showCheckBox(); return true; case 3:

showEditText(); return true; case 4:

showRadioGroup(); return true; case 5:

showSpinner(); return true;

return true;

public void showButton() {

Intent showButton = new Intent(this, testButton.class); startActivity(showButton);

public void showAutoComplete(){

Intent autocomplete = new Intent(this, AutoComplete.class);

startActivity(autocomplete);

public void showCheckBox(){

Intent checkbox = new Intent(this, testCheckBox.class); startActivity(checkbox);

public void showEditText() {

Intent edittext = new Intent(this, testEditText.class); startActivity(edittext);

Launch your application and select the EditText option from the Menu (shown earlier in Figure 8-1).

The following illustration shows what the EditText Activity looks like.

Click the Change Layout and Change Test Color Buttons. The results are depicted in the following illustrations.

0 0

Post a comment