|
Selecting Female & pushing DISPLAY ⇒ |
|
|
|
package com.example.wenchen.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends Activity {
private RadioGroup radioSexGroup;
private RadioButton radioSexButton;
private Button btnDisplay;
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
addListenerOnButton( );
}
public void addListenerOnButton( ) {
radioSexGroup = (RadioGroup) findViewById( R.id.radioSex );
btnDisplay = (Button) findViewById( R.id.btnDisplay );
btnDisplay.setOnClickListener( new OnClickListener( ) {
@Override
public void onClick( View v ) {
// Get selected radio button from radioGroup.
int selectedId = radioSexGroup.getCheckedRadioButtonId( );
// Find the radiobutton by returned id.
radioSexButton = (RadioButton) findViewById( selectedId );
Toast.makeText( MainActivity.this,
radioSexButton.getText( ), Toast.LENGTH_LONG ).show( );
}
});
}
}
|
|
A car hit an elderly man. The paramedic says, “Are you comfortable?” The man says, “I make a good living.” |