2016-05-18 51 views
1

我有一個Alertdialog,風格是複選框,我需要在彼此之間加一條線。
因爲我的物品太多了。 感謝您的幫助。AlertDialog,Checkbox之間應該有一條線

這是我的代碼

public Button.OnClickListener IMBL = new Button.OnClickListener() { 
    public void onClick(View v) { 
     AfterClick = new boolean[items.length]; 
     for (int i = 0; i < AfterClick.length; i++) { 
      AfterClick[i] = false; 
     } 

     AlertDialog dialog = new AlertDialog.Builder(Daycarddd.this) 
       .setTitle("skill") 
       .setMultiChoiceItems(items, AfterClick, 
         new DialogInterface.OnMultiChoiceClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, 
            int indexSelected, boolean isChecked) { 
           if (isChecked) { 

            for (int i = 0; i < AfterClick.length; i++) { 
             if (AfterClick[i]) { 
             } 

            } 
           } else if (seletedItems 
             .contains(indexSelected)) { 
            // Else, if the item is already in the 
            // array, remove it 
            seletedItems.remove(Integer 
              .valueOf(indexSelected)); 
           } 
          } 
         }) 
       .setPositiveButton("confirm", 
         new DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, 
            int id) { 

           for(int j=0;j< items.length;j++){           
            if(AfterClick[j]==true){    

            if(resultcheck==""){resultcheck=items[j];}else 
             resultcheck =resultcheck+","+items[j] ; 
            } 
            } 
           checkbox=resultcheck; 
           resultcheck=""; 
           Toast.makeText(Daycarddd.this, 
             checkbox, 
             Toast.LENGTH_SHORT).show(); 
          } 
         }) 
       .setNegativeButton("cancle", 
         new DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, 
            int id) { 
          } 
         }).create(); 
     dialog.show(); 
    } 
}; 
+0

顯示XML代碼 –

+0

@saint:我想你應該創建自定義佈局:) – AndiGeeky

+0

https://www.dropbox.com/ s/1mhj2cqj5nmvlnu/13262127_1221895697830046_1137746837_o.png?dl = 0喜歡這條紅線 – saint

回答

0

繪製一條水平線使用此佈局

 <View 
      android:id="@+id/viewBorder" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/darker_gray" 
      /> 

//這裏虛增您的自定義對話框

LayoutInflater inflater = getActivity().getLayoutInflater(); 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 

    final View view = inflater.inflate(R.layout.custom_dialog, null); 
    final EditText edTxtAmount = (EditText) view.findViewById(R.id.edTxtOffer); 
    builder.setTitle("Make Your Offer") 
      .setView(view) 
      .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 

        // Clicked 'Okay' 
       } 
      }) 
      .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        // Clicked 'Cancel' 
       } 
      }); 
    return builder.create(); 
} 

//自定義佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
<CheckBox 
    android:id="@+id/mCheckbox" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Your Check Box with border"/> 
<View 
    android:id="@+id/viewBorder" 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:layout_below="@id/mCheckbox" 
    android:background="@android:color/holo_red_dark"/>  

//的setView(視圖)將設置您的自定義對話框視圖

+0

如何添加此視圖? – saint

+0

在每個複選框後在你的xml中添加這個........... – sushildlh

+0

這個alertdialog複選框沒有xml .. – saint