android– 如何添加代码,当单击文本(textview)时,将出现一个图像(功能类似于警告对话框).

android– 如何添加代码,当单击文本(textview)时,将出现一个图像(功能类似于警告对话框).,第1张

概述Questions.javapublicvoidonClick(Viewv){if(q1.isChecked()){intcount=0;for(CheckBoxcb:cbList){if(cb.isChecked()){count++;

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)时,将出现一个类似的图像(如警告对话框).

解决方法:

使用自定义AlertDialog

@OverrIDepublic 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);    ...
总结

以上是内存溢出为你收集整理的android – 如何添加代码,当单击文本(textview)时,将出现一个图像(功能类似于警告对话框).全部内容,希望文章能够帮你解决android – 如何添加代码,当单击文本(textview)时,将出现一个图像(功能类似于警告对话框).所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1099243.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存