我有一个像这样的简单汽车数据库:
db.addCar(new Car("Alfa Romeo","Giulietta","1.4 TB Distinctive","Benzine","1.4","120","2012","5","1465","4351","54000"));
db.addCar(new Car("Audi","A6","2.0 TDi","Diesel","2.0","170","2012","6","1455","4915","183600"));
db.addCar(new Car("BMW","7 Series","7.30 ID Comfort","Benzine","3.0","245","2012","6","1450","4835","528000"));
db.addCar(new Car("Chevrolet","Captiva","2.0 LT AT","Diesel","2.0","163","2012","6","1756","4673","79950"));
db.addCar(new Car("Citroen","C5","1.6 HDi Comfort","Diesel","1.6","112","2012","5","1458","4779","67430"));
我正在使用 3 个微调器来选择前三列(品牌、型号、类型),我也可以使用这种方法将它们发送到我的结果 xml 页面
b3.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View comparePage2, MotionEvent event) {
Intent intent = new Intent(getApplicationContext(), Compare2.class);
//Create a bundle object
Bundle car = new Bundle();
//Inserts a String value into the mapping of this Bundle
car.putString("make", spinner_make.getSelectedItem().toString());
car.putString("model", spinner_model.getSelectedItem().toString());
car.putString("type", spinner_type.getSelectedItem().toString());
car.putString("make2", spinner_make2.getSelectedItem().toString());
car.putString("model2", spinner_model2.getSelectedItem().toString());
car.putString("type2", spinner_type2.getSelectedItem().toString());
//Add the bundle to the intent.
intent.putExtras(car);
//start the DisplayActivity
startActivity(intent);
return false;
}
private void loadSpinnerData() {
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
List <String> makers = db.getAllMakers();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, makers);
List <String> models = db.getAllModels();
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, models);
List <String> types = db.getAllTypes();
ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, types);
List <String> makers2 = db.getAllMakers();
ArrayAdapter<String> dataAdapter4 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, makers2);
List <String> models2 = db.getAllModels();
ArrayAdapter<String> dataAdapter5 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, models2);
List <String> types2 = db.getAllTypes();
ArrayAdapter<String> dataAdapter6 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, types2);
spinner_make.getContext();
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner_make.setAdapter(dataAdapter);
spinner_model.setAdapter(dataAdapter2);
spinner_type.setAdapter(dataAdapter3);
spinner_make2.setAdapter(dataAdapter4);
spinner_model2.setAdapter(dataAdapter5);
spinner_type2.setAdapter(dataAdapter6);
}
但是我如何使用相同的方法将其他字段发送到该 xml 页面?