我如何可以访问一个DialogBox的该领域的EditText? [英] How can I access the EditText field in a DialogBox?

查看:111
本文介绍了我如何可以访问一个DialogBox的该领域的EditText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以访问一个DialogBox的该领域的EditText?

How can I access the EditText field in a DialogBox?

推荐答案

将您的EditText小部件到您的对话框:

Place your EditText widget into your dialog:

<?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="wrap_content"
    android:orientation="vertical">

    <EditText
        android:id="@+id/myEditText"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" />
</LinearLayout>

然后从你的对话框内膨胀的视图,并获得的EditText的内容。

Then inflate the View from within your Dialog and get the content of the EditText.

private Dialog myTextDialog() {
    final View layout = View.inflate(this, R.layout.myDialog, null);

    final EditText savedText = ((EditText) layout.findViewById(R.id.myEditText));

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(0);

    builder.setPositiveButton("Save", new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
           String myTextString = savedText.getText().toString().trim();
        }
    });
    builder.setView(layout);
    return builder.create();
 }

pressing保存 - 按钮 myTextString 后,将持有你的EditText的内容。你当然需要显示这个例子中第一个对话框。

After pressing the "Save"-button myTextString will hold the content of your EditText. You certainly need to display the dialog of this example first.

这篇关于我如何可以访问一个DialogBox的该领域的EditText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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