现在的位置: 首页 > 综合 > 正文

RadioGroup RadioButton 和 自定义对话框(自定义确定和取消)

2013年01月12日 ⁄ 综合 ⁄ 共 3875字 ⁄ 字号 评论关闭

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="230dp"
    android:layout_height="wrap_content"
    android:background="@drawable/dgxml"
    android:orientation="vertical" >
   <TextView  
    android:id="@+id/dg_title_p"  
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:layout_centerHorizontal="true"
    android:text="选择支付方式"
    android:textSize="20sp"
    android:textColor="@color/white"
        />
    
    
    <RadioGroup
      android:id="@+id/RadioGroup01"  
      android:layout_below="@+id/dg_title_p"
      android:layout_marginTop="10dp"
      android:orientation="vertical"
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true"   
      android:layout_width="wrap_content"
         android:layout_height="wrap_content"
     >
      <RadioButton  
         android:text="多种支付方式"
         android:id="@+id/rbt_1"   
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textSize="15sp"
         android:textColor="@color/white"
       /> 
      <RadioButton  
         android:text="手机充值卡支付"
         android:id="@+id/rbt_2"   
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" 
         android:textSize="15sp"
         android:textColor="@color/white" 
       /> 
       <RadioButton  
         android:text="游戏点卡支付"
         android:id="@+id/rbt_3"   
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" 
         android:textSize="15sp"
         android:textColor="@color/white"        
       />  
    </RadioGroup>
    
     <LinearLayout 
        android:layout_width="230dp"
        android:layout_height="wrap_content"
       android:layout_marginTop="10dp"
        android:layout_below="@+id/RadioGroup01"
       android:layout_marginBottom="10dp" 
        android:orientation="horizontal"
        > <!--  android:gravity="bottom|center_horizontal"   android:layout_centerInParent="true" -->
        <Button 
            android:id="@+id/dg_button_ok_p"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
             android:layout_weight="1"
            android:text="确定"/>  <!--  android:layout_alignParentLeft="true"   -->
        <Button 
            android:id="@+id/dg_button_cancel_p"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          
             android:layout_weight="1"
            android:gravity="center"
            android:text="取消"/>   
            
        </LinearLayout>
    
    
    
</RelativeLayout>

 

 

private void select3_Dialog(String s ){
	    amount = s;
		LayoutInflater inflater =  (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view_P = inflater.inflate(R.layout.diag_pay3, null);
		s_Dialog = new Dialog(this,R.style.dialog);
		s_Dialog.setContentView(view_P);
		s_Dialog.setCancelable(false);
		//s_Dialog.setCanceledOnTouchOutside(true);
		TextView tv_title = (TextView)view_P.findViewById(R.id.dg_title_p);
		tv_title.setText("充值"+ Integer.parseInt(amount)/100 +"元,选择支付方式");
		final RadioGroup RadioGroup01 = (RadioGroup)view_P.findViewById(R.id.RadioGroup01);
		RadioButton rb1 = (RadioButton)view_P.findViewById(R.id.rbt_1);
		RadioButton rb2 = (RadioButton)view_P.findViewById(R.id.rbt_2);
		RadioButton rb3 = (RadioButton)view_P.findViewById(R.id.rbt_3);
		Button dg_button_ok = (Button)view_P.findViewById(R.id.dg_button_ok_p); 
		Button dg_button_cancel= (Button)view_P.findViewById(R.id.dg_button_cancel_p); 
		RadioGroup01.setOnCheckedChangeListener(new OnCheckedChangeListener () {
			public void onCheckedChanged(RadioGroup arg0, int checkedId) {
				if(checkedId==R.id.rbt_1){
					Toast.makeText(Activitycharge.this,"A选中", Toast.LENGTH_LONG).show();
					 select ="A";
				}
				if(checkedId==R.id.rbt_2){
					 Toast.makeText(Activitycharge.this,"B选中", Toast.LENGTH_LONG).show();
					 select ="B";
				}
				if(checkedId==R.id.rbt_3){
					Toast.makeText(Activitycharge.this,"C选中", Toast.LENGTH_LONG).show();
					 select ="C";
				}
			}
		});
		dg_button_ok.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if(check()==true){
					 if(select.equals("A")){
						 conneed(Integer.parseInt(amount), (Integer.parseInt(amount)+1)  );
					 }
					 if(select.equals("B")){
						 startPay(CUSTOMER_NUMBER, "CH_MOBILE",amount);
					 }
					 if(select.equals("C")){
						 startPay(CUSTOMER_NUMBER, "CH_GAME",amount);
					 }
					  
				}	 
			}
		});
		dg_button_cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				s_Dialog.dismiss();
				if(select!=null){select ="";}
			}
		});
		s_Dialog.show();
	}	

 效果图

    

 

抱歉!评论已关闭.