gpt4 book ai didi

android - 在android中设置单选AlertDialog默认项

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:32:27 26 4
gpt4 key购买 nike

<分区>

我正在使用以下代码创建一个 AlertDialog

    CharSequence[] array = {"Font1", "Font2", "Font3", "Font4"};
callback = (DialogClickListener) fragment;

builder = new AlertDialog.Builder(context);
builder.setTitle("Font Settings")
.setSingleChoiceItems(array, 0, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
selected = array[arg1].toString();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
callback.onYesClick(selected);
}
});

如何设置默认选中的元素?请帮助:)

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