我使用了三个复选框,如果选中了所有三个复选框,则单击“按钮”时,它会转到如果条件,否则会转到其他条件(即如果选中一个或两个或没有复选框),我只是想知道是否发生任何异常。 CheckBox.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class CheckBox extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.checkbox);
Button btn =(Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
TextView txt =(TextView) findViewById(R.id.txt);
android.widget.CheckBox chk1 =(android.widget.CheckBox) findViewById(R.id.chk1);
android.widget.CheckBox chk2 =(android.widget.CheckBox) findViewById(R.id.chk2);
android.widget.CheckBox chk3 =(android.widget.CheckBox) findViewById(R.id.chk3);
if (chk1.isChecked()==true&&chk2.isChecked()==true&&chk3.isChecked()==true) {
txt.setText("selected locations are"+chk1.getText().toString()+","+chk2.getText().toString()+","+chk3.getText().toString());
}
else{
txt.setText("select all locations");
}
}
}