从光标在安卓填写微调 [英] Fill spinner from cursor in android

查看:153
本文介绍了从光标在安卓填写微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找今天awnser的这一段时间。这一切看起来那么容易,但我从来没有得到它的工作。我想填补了微调与我的光标。我一直在尝试使用SimpleCursorAdapter基于这一点,很多网站说我会,但我从来没有得到它的工作。让我看看这是多么简单:)

感谢您的时间!

我的光标

 光标光标= db.query(DATABASE_TABLE_Clients,新的String [] {_id,C_Name},NULL,NULL,NULL,NULL,C_Name);
 

我的微调

 (微调)findViewById(R.id.spnClients);
 

我的code

 光标cursor_Names = SQLData.getClientNames();
startManagingCursor(cursor_Names);

的String []列=新的String [] {C_Name};
INT []到=新INT [] {R.id.txt_Address};

SimpleCursorAdapter mAdapter =新SimpleCursorAdapter(这一点,android.R.layout.simple_spinner_dropdown_item,cursor_Names,列,到);
微调spnClients =(微调)findViewById(R.id.spnClients);
spnClients.setAdapter(mAdapter);
 

解决方案

我没有看到你的code以便为您的下拉列表。是这样的:

  mAdapter.setDropDownViewResource(R.layout.spinner_view_dropdown);
 

当然,你需要有一个spinner_view_dropdown.xml文件在您的RES /布局目录。

i have searched for a awnser for this for a while today. It all looks so easy but i never get it to work. I want to fill a spinner with my cursor. I have been trying to use SimpleCursorAdapter for this as a lot of sites say i shall but i never get it to work. Show me just how easy it is :)

Thanks for your time!

My cursor

Cursor cursor = db.query(DATABASE_TABLE_Clients, new String[] {"_id", "C_Name"}, null, null, null, null, "C_Name");

My spinner

(Spinner) findViewById(R.id.spnClients);

My Code

Cursor cursor_Names = SQLData.getClientNames();
startManagingCursor(cursor_Names);

String[] columns = new String[] { "C_Name" };
int[] to = new int[] { R.id.txt_Address };

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_dropdown_item, cursor_Names, columns, to);
Spinner spnClients = (Spinner) findViewById(R.id.spnClients);
spnClients.setAdapter(mAdapter);

解决方案

I don't see a View for your dropdown in your code. Something like:

mAdapter.setDropDownViewResource(R.layout.spinner_view_dropdown);

Of course you need to have a spinner_view_dropdown.xml file in your res/layout directory.

这篇关于从光标在安卓填写微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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