Using AlertBuilder with cursors

别来无恙 提交于 2019-12-02 03:16:00

问题


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)

Thanks


回答1:


You should be able to do:

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.



来源:https://stackoverflow.com/questions/4500637/using-alertbuilder-with-cursors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!