我正在尝试使用以下代码创建列表对话框
new AlertDialog.Builder(ContactActivity.this)
.setTitle(contactStore.getContactName())
.setItems(contactStore.getContactNumber(),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.create();
但是它以下面的形式显示数据
但是我想创建这样的东西
因此,要实现此目的,我是否需要创建自定义对话框并在其中加载 ListView ?
最佳答案
不使用 setItems(),而是使用 setAdapter()。示例:
return new AlertDialog.Builder(getActivity())
.setTitle(getArguments().getString("titulo"))
.setCancelable(false)
.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.listrowlay, lista),
new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int item){
您可以使用您的布局代替 R.layout.listrowlay。
关于android - 在android中自定义对话框列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329156/