使用AlertBuilder使用游标 [英] Using AlertBuilder with cursors

查看:227
本文介绍了使用AlertBuilder使用游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要一个AlertDialog显示从光标数据库中选择的国家的名单,它选择的id和国名,我有以下的code,但我不知道怎么去选择的项目:

I want an AlertDialog to show a list of countries selected from database with a cursor, it selects id and country name, I have the following code but I don't know how to get the selected item:

AlertDialog.Builder ab=new AlertDialog.Builder(this);
ab.setTitle(R.string.msg_title_Pais_Resid);
Locale locale = Locale.getDefault();
final Cursor items  = DaoProvider.getListaPaisesCursor(this, (locale.getLanguage()).toUpperCase());

    ab.setCursor(items,new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Here: get the selected item object (or id)
        }
    }, Internacionalizacion.colInternacionalizacionTraduccion)

感谢

推荐答案

您应该能够做到:

items.moveToPosition(which)
String text = items.getString(THE_COLUMN_NUMBER)

参数是被点击的按钮,或选择该项目的位置(在列表中的情况下)。文档是这里

The which parameter is either the button that was clicked, or the position of the item that was selected (in the case of a list). Docs are here.

这篇关于使用AlertBuilder使用游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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