gpt4 book ai didi

java - 如何使警报对话框中的复选框左对齐?

转载 作者:太空宇宙 更新时间:2023-11-04 14:37:42 25 4
gpt4 key购买 nike

可以修改警报对话框中的复选框左对齐吗?

这是activity.java文件

AlertDialog dialog; 

final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
// arraylist to keep the selected items
final ArrayList seletedItems=new ArrayList();

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select The Difficulty Level");
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

}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Your code when user clicked on Cancel

}
});

dialog = builder.create();//AlertDialog dialog; create like this outside onClick
dialog.show();
}

...................................................... ………………

/image/rTpYb.jpg">

但是...我希望复选框显示在左侧...任何人都可以帮助我。

最佳答案

您可以将自定义 View 放入警报对话框中。在该 View 中,您可以轻松地将复选框对齐到您想要的位置。有关更多信息,请阅读本教程。 http://www.pcsalt.com/android/create-alertdialog-with-custom-layout/#sthash.yN5edpAX.FKWQjxBj.dpbs

关于java - 如何使警报对话框中的复选框左对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com