我正在尝试使用微调器通过我的数据库实现用户搜索。
我有车队和车辆(车队包含车辆)。我有一个车队列表作为一个微调器,一个车辆列表作为另一个。
默认情况下,我希望将车队设置为“全部”,并且将车辆设置为显示所有车辆(目前是这种情况),但是当车队输入更改为特定的车辆时,例如车队 1,车辆微调器应更新因此[这将通过 SQLite 数据库搜索来实现,但我认为问题不在这里]。
当车队微调器数据发生更改时,如何创建监听器?
vehicleSpinner = (Spinner) findViewById(R.id.vehicleSpinner);
String selected = (String)fleetSpinner.getSelectedItem();
ArrayAdapter<String> adapter5 = null;
if(selected == "All"){
//show all vehicles
adapter5 = new ArrayAdapter<String>(this, R.layout.sherlock_spinner_item, vehicleArrayListString);
}else{
String vehiclesInFleetQuery = "SELECT * FROM " + Database.TABLE_VEHICLE + " WHERE " + Database.COLUMN_FLEET + "='" + selected +"'";
Log.i(TAG,"QUERY: "+ vehiclesInFleetQuery);
Cursor cursor = Database.listOfVehiclesDesired(query);
if(cursor.moveToFirst()){
do {
String addToList = cursor.getString(cursor.getColumnIndex(Database.COLUMN_VEHICLE_ID));
vehicleArrayFleet.add(addToList);
} while (cursor.moveToNext());
}else{//error on fleet search, no vehicles in fleet
vehicleArrayFleet = vehicleArrayListString;
builderContinue.setMessage("Selected Fleet(" + selected + ") had zero associated vehicles").setTitle("Error").show();
}
if (cursor != null && !cursor.isClosed()) {
System.out.println("Closed");
cursor.close();
}
adapter5 = new ArrayAdapter<String>(this, R.layout.sherlock_spinner_item, vehicleArrayFleet);
}
adapter5.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
vehicleSpinner.setAdapter(adapter5);