我写的是Android应用程序。我有一个按钮,当点击它时,会出现一个警告对话框。此对话框中有12个复选框。我的问题是所有复选框都重叠。 我的活动是:
public class Get_CheckboxActivity extends Activity {
private String result="";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_report);
View checkBoxView = View.inflate(this, R.layout.checkbox, null);
final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox);
final CheckBox checkBox1 = (CheckBox) checkBoxView.findViewById(R.id.checkbox1);
final CheckBox checkBox2 = (CheckBox) checkBoxView.findViewById(R.id.checkbox2);
final CheckBox checkBox3 = (CheckBox) checkBoxView.findViewById(R.id.checkbox3);
final CheckBox checkBox4 = (CheckBox) checkBoxView.findViewById(R.id.checkbox4);
final CheckBox checkBox5 = (CheckBox) checkBoxView.findViewById(R.id.checkbox5);
final CheckBox checkBox6 = (CheckBox) checkBoxView.findViewById(R.id.checkbox6);
final CheckBox checkBox7 = (CheckBox) checkBoxView.findViewById(R.id.checkbox7);
final CheckBox checkBox8 = (CheckBox) checkBoxView.findViewById(R.id.checkbox8);
final CheckBox checkBox9 = (CheckBox) checkBoxView.findViewById(R.id.checkbox9);
final CheckBox checkBox10 = (CheckBox) checkBoxView.findViewById(R.id.checkbox10);
final CheckBox checkBox11 = (CheckBox) checkBoxView.findViewById(R.id.checkbox11);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox.getText().toString());
}
});
checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox1.getText().toString());
}
});
checkBox2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox2.getText().toString());
}
});
checkBox3.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox3.getText().toString());
}
});
checkBox4.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox4.getText().toString());
}
});
checkBox5.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox5.getText().toString());
}
});
checkBox6.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox6.getText().toString());
}
});
checkBox7.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox7.getText().toString());
}
});
checkBox8.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox8.getText().toString());
}
});
checkBox9.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox9.getText().toString());
}
});
checkBox10.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox10.getText().toString());
}
});
checkBox11.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result=result.concat(checkBox11.getText().toString());
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("title")
.setView(checkBoxView)
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent (Get_CheckboxActivity.this,Add_ReportActivity.class);
// intent.putExtra("ckeck_res",result );
startActivity(intent); }
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
}
}
和checkbox.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkbox"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="c12"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox1"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c11"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox2"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c10"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox3"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c9"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox4"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c8"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox5"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c7"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox6"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c6"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox7"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c5"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox8"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c4"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox9"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c3"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox10"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c2"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<CheckBox
android:id="@+id/checkbox11"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:text="c1"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
</FrameLayout>
当我使用scrollview时,它停止了!有什么办法吗?