android Dialog

一.自定义

    dia.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/showDia"
     >
    <EditText
        android:id="@+id/msg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>

   LayoutInflater inflater=getLayoutInflater();
    View layout=inflater.inflate(R.layout.dia, (ViewGroup)findViewById(R.id.showDia));
    final EditText msg=(EditText) layout.findViewById(R.id.msg);
    AlertDialog.Builder builder=new Builder(MainActivity.this);
    builder.setTitle("输入信息").setView(layout).setPositiveButton("输出", new DialogInterface.OnClickListener() {
     
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
      Toast.makeText(getApplicationContext(),msg.getText().toString() , Toast.LENGTH_LONG).show();
      
     }
    }).create().show() ;

posted @ 2013-04-13 20:16  王贺blog  阅读(134)  评论(0编辑  收藏  举报