2012-01-12 167 views
0

我在加载应用程序之后试图让我的微调器填充数据时遇到了很多问题。我只是乱搞,并为车辆建立了一个数据库。所以我试图让一个微调器加载数据库数据到它。这是我在试图这样做的方法中使用的代码,但我的微调从未加载过我的数据库数据。如何让我的微调器填充数据库数据?

SQLiteDatabase db = database.getReadableDatabase(); 
Cursor cursor = db.rawQuery("SELECT vehicle_make, vehicle_model, vehicle_year FROM vehicles;", null); 
vehicleProfileSpinner = (Spinner) findViewById(R.id.vehicleProfileSpinner); 
startManagingCursor(cursor); 

String[] columns = {"vehicle_year", "vehicle_make", "vehicle_model"}; 
int[] theView = {R.id.vehicleProfileSpinner}; 
SimpleCursorAdapter vpsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_dropdown_item, cursor, columns, theView); 
vpsAdapter.setDropDownViewResource(R.layout.main); 
vehicleProfileSpinner.setAdapter(vpsAdapter); 

回答

0

在我的情况,而不是使用Simplecursoradapter,我创建了从光标条目阵列和创建ArrayAdapter并设置它列出。它工作完美。不知何故,Simplecursor适配器查找ID字段并导致问题,所以我忽略它并使用了Arrayadapter。我会尝试更新这个帖子,我发布了其他问题的示例。

0

有一件事是你需要的SimpleCusorAdapter。