我是Android的新人。我试图为不同的字符串阵列组成一个有条件的适配器(取决于字符串变量)。
TextView textPrompt;
textPrompt = (TextView)findViewById(R.id.textprompt);
final String acType = i.getStringExtra("type");
textPrompt.setText(acType);
if (acType == "400G"){
spinnerSurface = (Spinner) findViewById(R.id.spinnerSurface);
ArrayAdapter<CharSequence> adapterSurface = ArrayAdapter.createFromResource(
this, R.array.surface_option_1, android.R.layout.simple_spinner_item);
adapterSurface.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerSurface.setAdapter(adapterSurface);
}
else if (acType != "400G"){
spinnerSurface = (Spinner) findViewById(R.id.spinnerSurface);
ArrayAdapter<CharSequence> adapterSurface = ArrayAdapter.createFromResource(
this, R.array.surface_option, android.R.layout.simple_spinner_item);
adapterSurface.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerSurface.setAdapter(adapterSurface);
}
spinnerSurface.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
TextView tx = (TextView)v;
Log.i("
id",String.valueOf(tx.getText()));
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
I use a textPrompt to check value of acType. No matter acType is "400G" or not "400G", program will take acType as not "400G" thus R.array.surface_option is taken instead of R.array.surface_option1. Please help.