首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >setContentView for alertDialog

setContentView for alertDialog
EN

Stack Overflow用户
提问于 2014-04-16 02:51:08
回答 4查看 17.6K关注 0票数 3

如果它有两个textEdit,我想从提交的文本编辑中获得信息,但是不知道怎么做。我也不知道如何对普通对话框进行提交或取消按钮(我知道您可以在alertDialog上使用"setNegativeButton")。

那么如何将提交或取消添加到常规对话框中呢?这就是我目前正在做的工作:

代码语言:javascript
复制
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中获得信息?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-04-16 05:42:29

创建布局文件: custom.xml

代码语言:javascript
复制
<?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函数:

代码语言:javascript
复制
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();
          }
        });

这里有一个指向教程的链接,可以得到您想要的东西。

下面是一个关于堆栈溢出问题的链接,该问题提供了有关自定义对话框的信息。

票数 5
EN

Stack Overflow用户

发布于 2014-04-16 04:26:30

代码语言:javascript
复制
     protected void showCustomDialog(final int position) {
            final Dialog dialog;
            dialog = new Dialog(getActivity());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.alert_enter);
            EditText editText;
            EditText editText2;
            editText = (EditText)dialog.findViewById(R.id.abc);
            editText2 = (EditText)dialog.findViewById(R.id.abcd);
            buttonOK = (Button)dialog.findViewById(R.id.quantity_ok_button);
            buttonOK.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                        String text=editText.getText().toString();
                        String text2=editText2.getText().toString();
                        dialog.dismiss();
                }
            });
}

你可以试试这段代码。我这样做是为了从对话框中获得一个值。使用值文本和文本2。

票数 2
EN

Stack Overflow用户

发布于 2014-04-16 03:13:06

做你自己的对话

代码语言:javascript
复制
class YourDialog extends Dialog {

private TextView mTextView1, mTextView1;
private Button mButton1, mButton2;

public YourDialog(Context context) {
    super(context);


}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_email_dialog);

    // init your component from layout
    // and add listiner to them

}

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23098148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档