自定义Dialog

//布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="320dp"
    android:layout_height="450dp"
    android:background="@drawable/mine_bg_add_address"
    android:orientation="vertical"
    android:padding="5dp" >

    <RelativeLayout
        android:id="@+id/rl1"
        android:layout_width="match_parent"
        android:layout_height="50dp" >

        <TextView
            android:id="@+id/tv_shoujianrenname"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="收件人姓名"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_shoujianrenname"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/tv_shoujianrenname"
            android:background="@null" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#cccccc" />

    <RelativeLayout
        android:id="@+id/rl2"
        android:layout_width="match_parent"
        android:layout_height="50dp" >

        <TextView
            android:id="@+id/tv_shouhuodizhi"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="收货地址"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_shouhuodizhi"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/tv_shouhuodizhi"
            android:background="@null" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#cccccc" />

    <RelativeLayout
        android:id="@+id/rl3"
        android:layout_width="match_parent"
        android:layout_height="50dp" >

        <TextView
            android:id="@+id/tv_youzhengbianma"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="邮政编码"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_youzhengbianma"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/tv_youzhengbianma"
            android:background="@null" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#cccccc" />

    <RelativeLayout
        android:id="@+id/rl4"
        android:layout_width="match_parent"
        android:layout_height="50dp" >

        <TextView
            android:id="@+id/tv_lianxishouji"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="联系手机"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_lianxishouji"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/tv_lianxishouji"
            android:background="@null" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#cccccc" />

    <RelativeLayout
        android:id="@+id/rl5"
        android:layout_width="match_parent"
        android:layout_height="50dp" >

        <TextView
            android:id="@+id/tv_lianxidianhua"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="联系电话"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_lianxidianhua"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/tv_lianxidianhua"
            android:background="@null" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#cccccc" />
  <Button
      android:id="@+id/btn_queren"
      android:background="@drawable/cart_btn_submit"
      android:layout_width="100dp"
      android:layout_height="wrap_content"
      android:text="确认添加"
     android:layout_marginTop="10dp"
      android:textSize="18dp"
      android:layout_gravity="center"/>
</LinearLayout>

代码实现如下: 此文是以便我以后观看

package cn.tedu.day.view;


import cn.tedu.day.R;
import cn.tedu.day.entity.Address;
import cn.tedu.day.model.idao.IModel.AsyncTask;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class AddressDialog extends Dialog {
    private Context context;
    private EditText et1;// 收件人姓名
    private EditText et2;// 收获地址
    private EditText et3;// 密码
    private EditText et4;// 联系手机
    private EditText et5;// 联系电话
    private Button btnSubmit;
    private Callback callback;

    public AddressDialog(Context context, Callback callback) {
        super(context);
        this.context = context;
        this.callback = callback;
    }

    public AddressDialog(Context context, Context context2, Callback callback) {
        super(context);
        context = context2;
        this.callback = callback;
    }

    public AddressDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    public void show() {
        super.show();
        // 获取window对话框
        Window window = getWindow();
        // 设置背景图片
        window.setBackgroundDrawable(new ColorDrawable(000000));
        // 获取下载地址的视图
        // window.setContentView(R.layout.address_activity);
        View view = View.inflate(context, R.layout.dialog_add_address, null);
        window.setContentView(view);
        setViews(view);
        setOnClickListener();
    }

    private void setOnClickListener() {
        btnSubmit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Address address = new Address();
                address.setFull_address(et2.getText().toString());
                address.setMobile(et5.getText().toString());
                address.setPhone(et4.getText().toString());
                address.setPostalCode(et3.getText().toString());

                address.setReceiveName(et1.getText().toString());

//回调方法  当点击对话框的Button按钮时,此方法回调

                callback.submit(address);
            }
        });
    }

    public void setViews(View v) {
        et1 = (EditText) v.findViewById(R.id.et_shoujianrenname);
        et2 = (EditText) v.findViewById(R.id.et_shouhuodizhi);
        et3 = (EditText) v.findViewById(R.id.et_youzhengbianma);
        et4 = (EditText) v.findViewById(R.id.et_lianxishouji);
        et5 = (EditText) v.findViewById(R.id.et_lianxidianhua);
        btnSubmit = (Button) v.findViewById(R.id.btn_queren);
    }

    public interface Callback {
        void submit(Address address);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值