开发者

Using AlertBuilder with cursors

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜