天天看点

自定义Dialog,带textview,EditText,Button

代码:

LayoutInflater inflater=getLayoutInflater();

      View layout=inflater.inflate(R.layout.request_info,(ViewGroup)findViewById(R.id.request_dialog));

      new AlertDialog.Builder(VisitorGrid.this)

      .setTitle("填写消息").setView(layout).

      setPositiveButton("确定",new DialogInterface.OnClickListener(){

       @Override

       public void onClick(DialogInterface dialog, int which) {

        // TODO Auto-generated method stub

        dialog.dismiss();

//        邀请指令格式:requestfriend#发送方#邀请方#附加信息

       }

      })

      .setNegativeButton("取消",new DialogInterface.OnClickListener(){

       @Override

       public void onClick(DialogInterface dialog, int which) {

        // TODO Auto-generated method stub

        dialog.dismiss();

       }

      }).show();

布局文件:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout

 xmlns:android="http://schemas.android.com/apk/res/android"

 android:layout_height="wrap_content" android:layout_width="wrap_content"

 android:orientation="vertical"

 android:id="@+id/request_dialog"

>

 <TextView

  android:id="@+id/request_title"

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:text="验证消息:"

 />

 <EditText

  android:id="@+id/request_content"

  android:layout_width="fill_parent"

  android:layout_height="wrap_content"

 />

</LinearLayout>

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fuuckwtu/archive/2011/02/12/6181425.aspx