Res/layout/Main. xml
<? XML version = "1.0" encoding = "UTF-8" ?> < Linearlayout Xmlns : Android = Http://schemas.android.com/apk/res/android" Android : Orientation = "Vertical" Android : Layout_width = "Fill_parent" Android : Layout_height = "Fill_parent" > < Textview Android : Layout_width = "Fill_parent" Android : Layout_height = "Wrap_content" Android : Text ="@ String/hello" Android : ID = "@ + ID/tvtext" /> < Button Android : Layout_height = "Wrap_content" Android : Layout_width = "Wrap_content" Android : Text = "Button" Android : ID = "@ + ID/mbtn" > </ Button > </ Linearlayout >
Src/ex03_07.java
Package gphone. ex03_07; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. textview; public class ex03_07 extends activity {/** called when the activity is first created. */textview tvtext = NULL; button mbtn = NULL; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); tvtext = (textview) This. findviewbyid (R. id. tvtext); mbtn = (button) This. findviewbyid (R. id. mbtn );Mbtn. setonclicklistener (New onclicklistener () {public void onclick (view v) {// todo auto-generated method stubtvtext. settext ("Hi, every body !!!! ");}});}}
Running result