You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中如何在AlertDialog中批量显示ArrayList中的多条数据

在AlertDialog中一次性显示多条列表数据的方法

你可以通过以下两种常见方式实现:

方法一:使用AlertDialog内置ListView展示(推荐)

这种方式适配数据量较多的场景,自带滚动效果,实现成本低:

// 获取你的人员列表数据
ArrayList<String> doctorList = getunfiledRogspDoctorList();

// 创建对话框构建器
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("未提交人员清单");

// 设置列表项及点击事件(点击逻辑可选)
builder.setItems(doctorList.toArray(new String[0]), new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // 点击单条数据的处理逻辑,比如弹出提示
        Toast.makeText(getApplicationContext(), doctorList.get(which), Toast.LENGTH_SHORT).show();
    }
});

// 弹出对话框
builder.create().show();

如果需要自定义列表项样式(比如显示多字段布局),可以用自定义Adapter替换默认实现:

ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_2, doctorList);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // 自定义点击逻辑
    }
});
builder.create().show();

方法二:拼接字符串用TextView显示

如果数据量较少,可将列表内容拼接成带换行的字符串,直接通过setMessage展示:

ArrayList<String> doctorList = getunfiledRogspDoctorList();

// 拼接每条数据,换行分隔
StringBuilder content = new StringBuilder();
for (String item : doctorList) {
    content.append(item).append("\n");
}

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("未提交人员清单")
       .setMessage(content.toString())
       .setPositiveButton("确定", null)
       .create()
       .show();

另外注意你代码中的SQL语句细节:SQL中判断相等用=而非==,可修正为:

String gspQuery = " SELECT * FROM "+ TABLE_DOCTOR + " WHERE " + Queryclass.DOCTOR_ROGSP_STATUS + " = " + 0 + " AND " + Queryclass.DOCTOR_DATE_ID + " = '" + selectionID + "'";

内容的提问来源于stack exchange,提问作者Abm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 08:10:24