Questions.java
public void onClick(View v) {
if (q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count <= 1) {
new AlertDialog.Builder(this).setMessage(R.string.negative).show();
} else {
new AlertDialog.Builder(this).setMessage(R.string.positive).show();
}
}
}
question.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/q1a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/sas1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sas1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
注意:别介意复选框
如何添加代码,当单击文本(textview)时,会出现一个类似的图像(如警告对话框)。?
答案 0 :(得分:0)
使用自定义AlertDialog
@Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.my_own_custom_dialog);
dialog.setTitle("The Title...");
// set the custom dialog components
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.my_own_image_resource);
...