在dialog中获取Edittext的值

来源:互联网 发布:node 压力测试 编辑:程序博客网 时间:2024/06/06 09:20

首先写了一个包含edittext的dialog布局:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/rl_list_library_dialog"    android:layout_width="match_parent"    android:layout_height="match_parent">    <EditText        android:id="@+id/et_list_library_note"        android:layout_width="match_parent"        android:layout_height="150dp"        android:layout_centerInParent="true"        android:layout_marginLeft="20dp"        android:layout_marginRight="20dp"        android:background="@drawable/edit_text_n"        android:gravity="top" /></RelativeLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

下面dialog代码:

protected void dialog() {        final View layout = View.inflate(context, R.layout.item_list_library_note_dialog,                null);        AlertDialog.Builder builder = new AlertDialog.Builder(context);        builder.setTitle("添加备注");        builder.setIcon(R.drawable.tab_remark_nor);        builder.setMessage("文档:" + listDetail.getOriginname());        builder.setView(layout);        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                //获得dialog 中 edittext的值                etListLibraryNote = (EditText) layout.findViewById(R.id.et_list_library_note);                libraryNote = etListLibraryNote.getText().toString();                addLibraryNote();                Toast.makeText(context, "添加档备注", Toast.LENGTH_SHORT).show();            }        });        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                dialog.dismiss();            }        });        builder.create().show();    }
    0 0
    原创粉丝点击