ホームに戻る
ラジオボタン
package org.example.helloworld;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
public class HelloWorld extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);
RadioButton rb1 = new RadioButton(this);
RadioButton rb2 = new RadioButton(this);
rb1.setText("A");
rb2.setText("B");
RadioGroup rg = new RadioGroup(this);
rg.addView(rb1);
rg.addView(rb2);
rb1.setChecked(true);
ll.addView(rg);
rb1.setOnClickListener(new SampleClickListener());
rb2.setOnClickListener(new SampleClickListener());
}
class SampleClickListener implements OnClickListener
{
public void onClick(View v){
AlertDialog.Builder adlg;
adlg = new AlertDialog.Builder(HelloWorld.this);
adlg.setTitle("Test");
RadioButton rb = (RadioButton)v;
adlg.setMessage("Selected " + rb.getText());
adlg.setPositiveButton("YES", null);
adlg.show();
}
}
}