自定义android中的对话框列表

Hun*_*unt 2 android android-dialog

我正在尝试使用以下代码创建列表对话框

new AlertDialog.Builder(ContactActivity.this)
    .setTitle(contactStore.getContactName())
    .setItems(contactStore.getContactNumber(), 
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        })
    .create();
Run Code Online (Sandbox Code Playgroud)

但它以下列形式显示数据

在此输入图像描述

但我想创造这样的东西

在此输入图像描述

所以为了实现这一点,我需要创建自定义对话框并在其中加载listview吗?

And*_*cha 9

而不是使用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){
Run Code Online (Sandbox Code Playgroud)

您可以在R.layout.listrowlay的位置使用您的布局.