Res/layout/ex03_10.xml
<? XML version =" 1.0 "Encoding =" UTF-8 "?> <Absolutelayout xmlns: Android =" Http://schemas.android.com/apk/res/android "Android: Orientation =" Vertical "Android: layout_width =" Fill_parent "Android: layout_height =" Fill_parent "> <Radiogroup Android: layout_height =" Wrap_content "Android: layout_width =" Wrap_content "Android: Id =" @ + ID/rgsex "Android: Orientation =" Horizontal "Android: layout_x =" 100dip "Android: layout_y =" 60dip "> <Radiobutton Android: text =" @ String/sex_man "Android: layout_height =" Wrap_content "Android: layout_width =" Wrap_content "Android: checked =" True "Android: Id =" @ + ID/radio_man "> </Radiobutton> <radiobutton Android: text =" @ String/sex_woman "Android: layout_height =" Wrap_content "Android: layout_width =" Wrap_content "Android: Id =" @ + ID/radio_woman "> </Radiobutton> </radiogroup> <edittext Android: layout_height =" Wrap_content "Android: layout_width =" Wrap_content "Android: text =" Edittext "Android: Id =" @ + ID/etweight "Android: layout_x =" 97dip "Android: layout_y =" 133dip "> </Edittext> <button Android: text =" Button "Android: layout_height =" Wrap_content "Android: layout_width =" Wrap_content "Android: Id =" @ + ID/BTN "Android: layout_x =" 120dip "Android: layout_y =" 212dip "> </Button> </absolutelayout>
Res/layout/ex03_10_01.xml
<? XML version = "1.0" encoding = "UTF-8" ?> < Absolutelayout Xmlns : Android = Http://schemas.android.com/apk/res/android" Android : Layout_width = "Fill_parent" Android : Layout_height = "Fill_parent" > < Textview Android :Layout_height = "Wrap_content" Android : Layout_width = "Wrap_content" Android : Text = "Textview" Android : Layout_x = "126dip" Android : Layout_y = "144dip" Android : ID = "@ + ID/tvresult" > </ Textview > </ Absolutelayout >
Src/ex03_10.java
Package gphone. ex03_10; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. edittext; import android. widget. radiogroup; public class ex03_10 extends activity {button BTN = NULL; edittext etweight = NULL; radiogroup rgsex = NULL;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. ex03_10); BTN = (button) findviewbyid (R. id. BTN); etweight = (edittext) findviewbyid (R. id. etweight); rgsex = (radiogroup) findviewbyid (R. id. rgsex); BTN. setonclicklistener (New button. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubstring strweight = etweight. gettext (). tostring (); string strsex = "female"; if (rgsex. getcheckedradiobuttonid () = R. id. radio_man) {strsex = "male";} else {strsex = "female";} bundle B = new bundle (); B. putstring ("weight", strweight); B. putstring ("sex", strsex); intent = new intent (); intent. putextras (B); intent. setclass (ex03_10.this, ex03_10_01.class); startactivity (intent );}});}}
Src/ex03_10_01.java
Package Gphone. ex03_10; Import Android. App. activity; Import Android. OS. Bundle; Import Android. widget. textview; Public Class Ex03_10_01 Extends Activity {textview tvresult = Null ; @ Override Protected Void Oncreate (bundle savedinstancestate ){ // Todo auto-generated method stub Super . Oncreate (savedinstancestate); setcontentview (R. layout. ex03_10_01); tvresult = (textview) findviewbyid (R. Id. tvresult); bundle B = This . Getintent (). getextras (); string strweight = B. getstring (" Weight "); String strsex = B. getstring (" Sex "); Tvresult. settext (" Result: "+ Strweight +" , "+ Strsex );}}
Running result