我有一个带有 5 个微调器的选项页面。当用户登录并修改他们的帐户选项时,我希望微调器加载用户对微调器的选择。目前,每个微调器都会在其适配器“请选择”中加载第一个值。如果检查了服务器并且用户尚未做出选择,那很好 - 但我希望根据明显的条件来决定。
有没有好的方法来做到这一点?我刚刚完成了将微调器选项发送到服务器并将它们存储在适当用户旁边的代码。所以我知道我需要不同的 PHP 查询,这没问题。但是如何为 onCreate 中的微调器设置可见值?
ageSpinner = (Spinner) findViewById(R.id.ageSpinner);
ageAdapter = ArrayAdapter.createFromResource
(this, R.array.ageArray, android.R.layout.simple_spinner_item);
ageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ageSpinner.setAdapter(ageAdapter);
ageSpinner.setTag("age");
ageSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
eduSpinner = (Spinner) findViewById(R.id.eduSpinner);
eduAdapter = ArrayAdapter.createFromResource
(this, R.array.eduArray, android.R.layout.simple_spinner_item);
eduAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
eduSpinner.setTag("edu");
eduSpinner.setAdapter(eduAdapter);
eduSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
maritalSpinner = (Spinner) findViewById(R.id.maritalSpinner);
maritalAdapter = ArrayAdapter.createFromResource
(this, R.array.maritalArray, android.R.layout.simple_spinner_item);
maritalAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
maritalSpinner.setTag("marital");
maritalSpinner.setAdapter(maritalAdapter);
maritalSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
nationalitySpinner = (Spinner) findViewById(R.id.nationalitySpinner);
nationalityAdapter = ArrayAdapter.createFromResource
(this, R.array.nationalityArray, android.R.layout.simple_spinner_item);
nationalityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
nationalitySpinner.setTag("nationality");
nationalitySpinner.setAdapter(nationalityAdapter);
nationalitySpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if (pos != 0) {
param.add(new BasicNameValuePair(parent.getTag().toString(),
parent.getItemAtPosition(pos).toString()));
}
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}