Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.radiogenre;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- 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 rgjeniskelamin;
- private Button btPilih;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- rgjeniskelamin=(RadioGroup)findViewById(R.id.rgkelamin);
- btPilih=(Button)findViewById(R.id.btpilih);
- btPilih.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- int id=rgjeniskelamin.getCheckedRadioButtonId();
- if (id==-1) {
- Toast.makeText(MainActivity.this, "Jenis Kelamin Belum dipilih!!!", Toast.LENGTH_SHORT).show();
- } else {
- switch (id) {
- case R.id.rdlaki:
- Toast.makeText(MainActivity.this,
- "Saya Seorang "+((RadioButton)findViewById(id)).getText(),
- Toast.LENGTH_SHORT).show();
- break;
- case R.id.rdperempuan:
- Toast.makeText(MainActivity.this,
- "Saya Seorang "+((RadioButton)findViewById(id)).getText(),
- Toast.LENGTH_SHORT).show();
- break;
- default:
- break;
- }
- }
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement