ホームに戻る
チェックボックス
package org.example.test;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.widget.CompoundButton.*;
public class CheckBox extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);
CheckBox cb = new CheckBox(this);
cb.setText("Check?");
ll.addView(cb);
cb.setOnCheckedChangeListener(new SampleCheckedChangeListener());
}
class SampleCheckedChangeListener implements OnCheckedChangeListener
{
public void onCheckedChanged(CompoundButton cb, boolean isChecked){
AlertDialog.Builder adlg;
adlg = new AlertDialog.Builder(HelloWorld.this);
adlg.setTitle("Test");
adlg.setMessage("Checked");
adlg.setPositiveButton("YES", null);
if(isChecked == true){
adlg.show();
}
}
}
}