01 | package com.example.wenchen.myapplication; |
03 | import android.app.Activity; |
04 | import android.os.Bundle; |
05 | import android.view.View; |
06 | import android.view.View.OnClickListener; |
07 | import android.widget.Button; |
08 | import android.widget.RadioButton; |
09 | import android.widget.RadioGroup; |
10 | import android.widget.Toast; |
12 | public class MainActivity extends Activity { |
13 | private RadioGroup radioSexGroup; |
14 | private RadioButton radioSexButton; |
15 | private Button btnDisplay; |
18 | public void onCreate( Bundle savedInstanceState ) { |
19 | super .onCreate( savedInstanceState ); |
20 | setContentView( R.layout.activity_main ); |
21 | addListenerOnButton( ); |
24 | public void addListenerOnButton( ) { |
25 | radioSexGroup = (RadioGroup) findViewById( R.id.radioSex ); |
26 | btnDisplay = (Button) findViewById( R.id.btnDisplay ); |
27 | btnDisplay.setOnClickListener( new OnClickListener( ) { |
29 | public void onClick( View v ) { |
31 | int selectedId = radioSexGroup.getCheckedRadioButtonId( ); |
33 | radioSexButton = (RadioButton) findViewById( selectedId ); |
34 | Toast.makeText( MainActivity. this , |
35 | radioSexButton.getText( ), Toast.LENGTH_LONG ).show( ); |
|