自定义dialog对话框

dialog.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:padding="15dp"
    android:orientation="vertical"
    android:background="#ffffff" >

    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/dialog_sendText"
        android:text="@string/dialog_send"
        android:paddingLeft="10dp"
        android:textSize="18dp"
        android:textStyle="bold"
        />

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="10dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        >

        <ImageView 
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/headimage"
            />

        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:id="@+id/personname"
            android:textSize="18dp"
            />

    </LinearLayout>

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="10dp"
        >

        <EditText 
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"
            android:id="@+id/msg_text"
            android:background="@drawable/bg_edittext"  
            android:padding="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"  
            android:textColorHint="#AAAAAA"  
            android:textSize="15dip"  
            android:singleLine="true"   
            android:inputType="textMultiLine"
            android:gravity="left|top"
            android:minLines="6"
            />

    </LinearLayout>

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="15dp"
        android:divider="@drawable/layoutline"
        android:showDividers="middle"
        >

        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:id="@+id/button1"
            android:background="@drawable/conner_"
            >

            <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:id="@+id/text1"
                android:text="@string/quxiao"
                android:textSize="18dp"
                />

        </LinearLayout>

        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:id="@+id/button2"
            android:background="@drawable/conner_"
            >

            <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:id="@+id/text2"
                android:text="@string/queding"
                android:textSize="18dp"
                />

        </LinearLayout>



    </LinearLayout>

</LinearLayout>

一个button 点击事件包含对话框:

class PersonListClick implements OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> arg0, final View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            //装载/res/layout/login.xml界面布局  
            LinearLayout loginForm = (LinearLayout)getLayoutInflater().inflate(R.layout.dialog,null);
            ImageView headimage = (ImageView) loginForm.findViewById(R.id.headimage);
            TextView personname = (TextView) loginForm.findViewById(R.id.personname);
            EditText msgcontent = (EditText) loginForm.findViewById(R.id.msg_text);
            LinearLayout button1 = (LinearLayout) loginForm.findViewById(R.id.button1);//取消
            LinearLayout button2 = (LinearLayout) loginForm.findViewById(R.id.button2);//确定
            //处理内容
            ImageView image = (ImageView) arg1.findViewById(R.id.personimage);
            Bitmap bm = ((BitmapDrawable)image.getDrawable()).getBitmap();  
            headimage.setImageBitmap(bm);

            TextView text = (TextView) arg1.findViewById(R.id.personname);
            String name = text.getText().toString();
            personname.setText(name);

            Intent intent = getIntent();
            final String context = intent.getStringExtra("context");
            msgcontent.setText(context);

            //按钮点击事件
            button1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    finish();
                }
            });

            button2.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    TextView phone = (TextView) arg1.findViewById(R.id.personnumber);
                    String number = phone.getText().toString();
                    SmsManager manager = SmsManager.getDefault(); 
                    ArrayList<String> list = manager.divideMessage(context);  //因为一条短信有字数限制,因此要将长短信拆分  
                    for(String text:list){  
                        manager.sendTextMessage(number, null, text, null, null);  
                    }  
                    Toast.makeText(getApplicationContext(), "发送完毕", Toast.LENGTH_SHORT).show(); 

                }
            });

            // 设置对话框显示的View对象  
            builder.setView(loginForm);  

            //创建、并显示对话框  
            builder.create().show(); 

        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值