我是安卓新手。我试图为不同的字符串数组形成一个条件适配器(取决于一个字符串变量)。
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("\n\nid",String.valueOf(tx.getText()));
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
我使用 textPrompt 来检查 acType 的值。无论 acType 是“400G”还是非“400G”,程序都会将 acType 视为非“400G”,因此采用 R.array.surface_option 而不是 R.array.surface_option1。请帮忙。