2016-07-28 3 views
0

나는이 alertdialog를 갖고 싶지만 두 번째 헤더를 두 개로 나눈다.어떻게하면 안드로이드에서 alertdialog에 두 번째 헤더를 만듭니 까?

final CharSequence[] items = {" Cereal ", " Chocolate chips ", " Crunchy peanut butter ", " Vanilla ", " Espresso powder ", 
      " Kosher salt ", " Powdered sugar ", " Marshmallows "}; 
    // arraylist to keep the selected items 
    final ArrayList seletedItems = new ArrayList(); 

    builder = new AlertDialog.Builder(this); 
    builder.setTitle("Ingredients List"); 
    builder.setMultiChoiceItems(items, null, 
      new DialogInterface.OnMultiChoiceClickListener() { 
       // indexSelected contains the index of item (of which checkbox checked) 
       @Override 
       public void onClick(DialogInterface dialog, int indexSelected, 
            boolean isChecked) { 
        if (isChecked) { 
         // If the user checked the item, add it to the selected items 
         // write your code when user checked the checkbox 
         seletedItems.add(indexSelected); 
        } else if (seletedItems.contains(indexSelected)) { 
         // Else, if the item is already in the array, remove it 
         // write your code when user Uchecked the checkbox 
         seletedItems.remove(Integer.valueOf(indexSelected)); 
        } 
       } 
      }) 
      // Set the action buttons 
      .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int id) { 
        // Your code when user clicked on OK 
        // You can write the code to save the selected item here 

       } 
      }); 
    dialog = builder.create(); 
+1

R.layout.your_content_viewR.id.header 반드시 존재

TextView text = (TextView) dialog.findViewById(R.id.header); text.setText("Header text"); 

물론 :

는 헤더 텍스트를 설정 마십시오. 'AlertDialog'는 일반적인 외모와 느낌을 가진 일반적으로 사용되는'Dialog' 객체를 만드는 편리한 메소드로 사용됩니다. – DeeV

답변

0

에 AlertDialog 두 번째 헤더를 가질 수 있지만, 대화의 내용보기에 그것을 만들 수있는 콘텐츠보기를 사용 설정 :

dialog.setContentView(R.layout.your_content_view); 
을 여기

This is how the alertdialog current looks

코드입니다

레이아웃에서 R.layout.your_content_view 구조를 가질 수 있으므로 TextView를 추가 할 수 있습니다. 헤더처럼 아프다. 이 사용자 정의`Dialog`을 필요로

+0

이것은 올바른 방향으로 나를 가리켰다. 그리고 나는 그것을 이해했다. 도와 주셔서 감사합니다! –

+0

문제는 없습니다. @WesleySmith 당신에게 아무런 문제가 없다면 - 답변에 투표하고 옳은지 확인하십시오. 감사! –