如何把增加code文本(TextView的)被点击时,图像会出现(功能像一个警告对话框)。? [英] how to put add code that when the text(textview) is clicked, an image will appear(function like an alert dialog) .?

查看:102
本文介绍了如何把增加code文本(TextView的)被点击时,图像会出现(功能像一个警告对话框)。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Questions.java

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

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>

请注意:心中永远的复选框

note: never mind the checkbox

如何把增加code文本(TextView的)被点击时,图像会出现(像一个警告对话框)类似的东西?

how to put add code that when the text(textview) is clicked, an image will appear( like an alert dialog) something like that.?

推荐答案

通过自定义AlertDialog

With a custom 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);

    ...

这篇关于如何把增加code文本(TextView的)被点击时,图像会出现(功能像一个警告对话框)。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆