如何更新项目阵列中创建后建成AlertDialog.builder一个AlertDialog列表 [英] How to update array of items in an AlertDialog list built with AlertDialog.builder after creation

查看:190
本文介绍了如何更新项目阵列中创建后建成AlertDialog.builder一个AlertDialog列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个对话框,显示可以检查的项目,使用AlertDialog.builder的多选项列表。

I have created a dialog that shows a multi-choice list of items that can be checked, using AlertDialog.builder.

我设定的初始设定项目名称和它们的选中状态是这样的:

I set the initial set of item names and their checked state thus:

builder.setMultiChoiceItems( saveTargets.names, saveTargets.checked, new DialogInterface.OnMultiChoiceClickListener() {

在我的对话我也补充说,创建应显示并选择在多选择列表中的新项目的按钮。

In my dialog I have added a button that creates a new item that should be shown and be selectable in the multi-choice list.

我怎么能要求的对话来更新列表,以显示新的项目?

How can I ask the Dialog to update the list to show the new item?

我把它添加到我的saveTargets变量,但需要toset新的数据到的警告对话框的列表视图。

I have it added to my "saveTargets" variables, but need toset the new data into the list view in the alert dialog.

我试图用游标设置多选择。我不能使用,现在其他原因。

I tried using a cursor to setup the multi-choice. I can't use that now for other reasons.

我看着越来越ListView,并且从警报对话框中的适配器,但不能看到任何电话续约名称数组,并检查状态。

I've looked at getting the ListView and the Adaptor from the alert dialog, but can't see any calls to renew the array of names and checked status.

推荐答案

我需要做这样的事情也是如此。看后对谷歌,计算器和文档,它看起来比较不可能做而不做自己的适配器来处理列表(见:<一href="http://stackoverflow.com/questions/3594331/how-to-customize-the-list-items-in-an-android-alertdialog/3594562#3594562">How定制的一款Android AlertDialog 列表项)。因为我只需要这个了一个对话框,我结束了做什么文件说,不这样做:我在我自己的方法做了alertdialog,并没有让onCreateDialog在我的活动部分(我不得不这样做对于一系列的对话框另一类在我的应用程序以及)。这种方式的对话框从头每次被调用所以列表每次更新时重新创建。这是最简单的解决我能找到个人。不干净,也许,但更容易添加和作品像它应该。

I needed to do something like this as well. After looking on google, stackoverflow and the documentation, it looks like it relatively impossible to do without making your own adapter to handle the list (see: How to customize the list items in an Android AlertDialog). Since I only needed this for a single dialog, I ended up doing what the documentation says don't do: I made an alertdialog in my own method and did not make it part of "onCreateDialog" in my activity (I had to do this for a series of dialogs for another class in my app as well). This way the dialog is recreated from scratch each time it is called so the list is updated each time. That was the easiest fix I could find personally. Not as clean, maybe, but easier to add and works like it should.

这篇关于如何更新项目阵列中创建后建成AlertDialog.builder一个AlertDialog列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆