先看一下效果吧:

布局文件: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();// 显示对话框}

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

更多相关文章

  1. Android(安卓)调用相册或相机选择图片
  2. Android(安卓)调用前后摄像头同时拍照
  3. Android(安卓)取得对话框中EditText的字符串
  4. Android(安卓)对话框(Dialog)大全 建立你自己的对话框
  5. Rexsee API介绍:Android屏幕锁定,Keyguard函数与扩展源码
  6. Android(安卓)App调用跳转百度地图、高德地图、腾讯地图进行目的
  7. Android(安卓)集成百度地图实现设备定位
  8. Android调用JNI出错 java.lang.UnsatisfiedLinkError: No implem
  9. Android自动检测版本及自动升级

随机推荐

  1. docker入门到进阶四
  2. 原生购物车 Vue 改写
  3. docker入门到进阶三
  4. docker入门到进阶二
  5. OpenStack部署
  6. 使用PHPExcel导出excell,出现身份证用科学
  7. Xml简介_动力节点Java学院整理
  8. xpath简介_动力节点Java学院整理
  9. 简单了解XML 树结构
  10. Xpath语法格式总结