Android 实现多个输入框的对话框

来源:互联网 发布:java.io.file jar包 编辑:程序博客网 时间:2024/04/27 23:33

先看一下效果吧:

布局文件:dialog.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" >    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:text="@string/inownername" />    <EditText        android:id="@+id/ownername"        android:layout_width="wrap_content"        android:layout_height="wrap_content"         android:layout_marginLeft="40dp"        android:layout_marginRight="20dp"        android:ems="10">        <requestFocus />    </EditText>    <TextView        android:id="@+id/textView2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:text="@string/inownerphone" />    <EditText        android:id="@+id/ownerphone"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="40dp"        android:layout_marginRight="20dp"        android:ems="10" /></LinearLayout>

调用的方法:

protected void showAddDialog() {LayoutInflater factory = LayoutInflater.from(this);final View textEntryView = factory.inflate(R.layout.dialog, null);final EditText editTextName = (EditText) textEntryView.findViewById(R.id.ownername);final EditText editTextNumEditText = (EditText) textEntryView.findViewById(R.id.ownerphone);AlertDialog.Builder ad1 = new AlertDialog.Builder(LoginActivity.this);ad1.setTitle("添加业主信息:");ad1.setIcon(android.R.drawable.ic_dialog_info);ad1.setView(textEntryView);ad1.setPositiveButton("确定", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int i) {Log.i("111111", editTextName.getText().toString());Owner person = new Owner();person.setOwnername(editTextName.getText().toString());person.setOwnerphone(editTextNumEditText.getText().toString());}});ad1.setNegativeButton("取消", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int i) {}});ad1.show();// 显示对话框}

怎么样,是不是非常简单啊,呵呵.

0 0
原创粉丝点击