我正在使用動態和靜態微調。 這是我的代碼,我如何實現HashMap
來顯示用戶選擇的內容(值)?在spinners中使用HashMaps android studio
public class DatosAutoActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
private Spinner sp_marca, sp_modelo, sp_colores;
private TextView tvMarca, tvModelo, tvColor, tvPlacas;
private Button btn_enviarDatos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_datos_auto);
sp_marca = (Spinner)findViewById(R.id.sp_marca);
sp_modelo = (Spinner)findViewById(R.id.sp_modelo);
sp_colores = (Spinner)findViewById(R.id.sp_colores);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,
R.array.array_marcas,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp_marca.setAdapter(adapter);
sp_marca.setOnItemSelectedListener(this);
ArrayAdapter<CharSequence> adapterColor = ArrayAdapter.createFromResource(
this,
R.array.array_colores,
android.R.layout.simple_spinner_item);
adapterColor.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp_colores.setAdapter(adapterColor);
sp_colores.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
int[] marcas = {R.array.array_chevrolet, R.array.array_ford, R.array.array_honda,
R.array.array_nissan,R.array.array_renault, R.array.array_toyota,
R.array.array_volkswagen};
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,
marcas[position],
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp_modelo.setAdapter(adapter);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
@Override
protected void onResume() {
super.onResume();
btn_enviarDatos = (Button)findViewById(R.id.btn_enviarDatos);
btn_enviarDatos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent siguiente = new Intent(DatosAutoActivity.this, VerificacionDatosActivity.class);
startActivity(siguiente);
}
else {
Toast.makeText(getApplicationContext(), "Debes llenar todos los campos", Toast.LENGTH_SHORT).show();
}
});
}
}
待辦事項你想將'HashMap'數據傳遞給適配器? –