为的setContentView alertDialog [英] setContentView for alertDialog

查看:202
本文介绍了为的setContentView alertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对话框工作弹出里面,如果它有两个文本编辑的。我想获得从提交文本编辑的信息,但不知道怎么办。我不知道该怎么做(用setNegativeButton上alertDialog我知道你可以),一个提交或一个普通的对话框中取消按钮。

working on a dialog to pop up that inside if it has two textEdit's. I would like to get the information from the text edits on submit, but dont know how. I also dont know how to do a submit or a cancel button for a plain dialog ( i know you can on an alertDialog with "setNegativeButton").

那么,如何添加一个提交或取消到正规的对话?这就是我与迄今为止的工作:

So how do I add a submit or cancel to a regular dialog? this is what I am working with thus far:

public void changeEmail(View v){

    Dialog dialog =  new Dialog(this);
    dialog.setContentView(R.layout.change_email_dialog);
    dialog.setTitle("Enter your new email");
    dialog.show();


}

我想我也想知道,如果有人可以很快解释我怎么会得到两个textEdits属于该对话框被使用?

I guess also I was wondering if someone could quickly explain how I would get the info from the two textEdits that are inside of the layout that the dialog is using?

推荐答案

创建一个布局文件:custom.xml

create a layout file: custom.xml

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

    <TextView
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF"/>

</RelativeLayout>

创建按钮的点击下面的onClick功能(当你想要的对话框显示):

create the following onClick function on click of the button(when you want the dialog box to appear):

button.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View arg0) {

            // custom dialog
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom);
            dialog.setTitle("Title");

            // set the custom dialog components - text, image and button
            TextView text = (TextView) dialog.findViewById(R.id.text1);
            text.setText("Text view 1");

            TextView text = (TextView) dialog.findViewById(R.id.text2);
            text.setText("Text view 2");

            dialog.show();
          }
        });

下面是对教程链接获取什么你要。

Here is a link to the tutorial for getting exactly what you want.

下面是一个<一个href=\"http://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android\">link在堆栈溢出的问题,提供有关自定义对话框的信息。

Here is a link to a question on Stack Overflow which provides information about custom dialog box.

这篇关于为的setContentView alertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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