Page 203

186

Android: A Programmer’s Guide

changeOption(edittext); } }); final Button changeButton2 = (Button) findViewById(R.id.textColorButton); changeButton2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v){ changeOption2(edittext); } }); } public void changeOption(EditText edittext){ if (edittext.getHeight()==100){ edittext.setHeight(30); } else{ edittext.setHeight(100); } } public void changeOption2(EditText edittext){ edittext.setTextColor(Color.RED); } }

AndroidViews.java

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 import import import

android.app.Activity; android.os.Bundle; android.view.Menu; 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); }

McGraw.Hill.Android.A.Programmers.Guide.Jul.2008  

Android ™ A Programmer’s Guide This page intentionally left blank A Programmer’s Guide J.F. DiMarzio New York Chicago San Francisco Lisbon L...

McGraw.Hill.Android.A.Programmers.Guide.Jul.2008  

Android ™ A Programmer’s Guide This page intentionally left blank A Programmer’s Guide J.F. DiMarzio New York Chicago San Francisco Lisbon L...

Advertisement