我有一个包含
的表格------------------------
id |Name
------------------------
16001 |ABC
16002 |QWE
16003 |RTY
16004 |JHG
并将其绑定到微调器;带有名称的微调器项和带有id的spinneritemposition。
我到目前为止尝试了这个:
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, lables);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
List<String> lables = dataSource.getAllmothers();
public List<String> getAllmothers()
{
List<String> labels = new ArrayList<String>();
database = dbHelper.getReadableDatabase(); // Select All Query
String selectQuery = "SELECT id,name FROM "+dbHelper.TABLE_REGISTRATION;
Cursor cursor = database.rawQuery(selectQuery, null); // looping through all rows and adding to list
if (cursor.moveToFirst()) {
do
{
labels.add(Integer.toString(cursor.getInt(0)));
labels.add(cursor.getString(1));
} while (cursor.moveToNext());
} // closing connection
cursor.close();
database.close(); // returning lables
return labels;
}
答案 0 :(得分:0)
像这样创建数组适配器 ArrayAdapter ad = new ArrayAdapter(cureentclass,dropdownstyle,values)
值是您通过数据库值变量获取的值,并将Array Adapter绑定到微调器。