复选框AlertDialog"推出"通过TextView中 [英] Checkbox in AlertDialog "pushed out" by TextView

查看:194
本文介绍了复选框AlertDialog"推出"通过TextView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个AlertDialog展现在我的应用程序的介绍信息,与它下面一个不要再显示此复选框。

I'm trying to create an AlertDialog to show an introduction message in my application, with a "Don't show this again" CheckBox below it.

它运作良好,当AlertDialog的消息虽短,但过长时(需要滚动)的复选框不再显示。它得到了TextView的挤出。

It works well when the message of the AlertDialog is short, but when is too long (requiring scrolling) the CheckBox is no longer shown. It gets "pushed out" by the TextView.

XML的自定义视图(dont_show_again.xml):

The XML for the custom view (dont_show_again.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <CheckBox 
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Don't show this again">
    </CheckBox>
</LinearLayout>

而code显示AlertDialog

And the code to display the AlertDialog

String longMessage = getString(R.string.long_message);

LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.dont_show_again, null);

AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Some message")
.setMessage(longMessage)
.setView(checkboxLayout)
.setPositiveButton("Ok",
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
});

AlertDialog dialog = builder.create();
dialog.show();

如何解决这个任何想法?也许有人有这方面的AlertDialog的例子有不要再显示此复选框?

Any ideas on how to solve this? Perhaps someone has an example of a working AlertDialog with a "Don't show this again" CheckBox?

推荐答案

不要设置对话框的一封邮件,而不是将其包含在布局XML作为TextView的。

Dont set the dialog box messsage instead include it in the layout xml as textView.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">

<TextView
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"    
    android:singleLine="false"
    android:maxLines="3"
    android:scrollbars="vertical"/>
<CheckBox 
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Don't show this again">
</CheckBox> 
</LinearLayout>

这篇关于复选框AlertDialog&QUOT;推出&QUOT;通过TextView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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