私はこのalertdialogを持っていますが、次のリストを2つに分割する2番目のヘッダがあります。ここでandroidのalertdialogに2番目のヘッダを作成する方法
This is how the alertdialog current looks
コードです:
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();
R.layout.your_content_viewにR.id.header必見の存在
もちろん:
はちょうどヘッダーテキストを設定してください。 'AlertDialog'は、よく使われる' Dialog'オブジェクトを共通の外観と感じるようにするための便利なメソッドとして使われています。 – DeeV