需要从我的微调器 workRequestType 中选择的微调器加载信息。我现在开始在 java android 中编程,但我不确定如何执行此过程。
我做过的研究,我需要使用 setOnItemSelectedListener 但不知道如何使用。我在哪里声明这个过程?
我的java代码:
spnWorkRequesType.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String workRequestType = arg0.getItemAtPosition(arg2).toString();
loadCustomServiceSpinner(workRequestType);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}});
private void loadCustomServiceSpinner(String workRequestType) {
CustomServiceDBQueries csQueries = new CustomServiceDBQueries();
customService = csQueries.selectCustomService(workRequestType);
String[] strCustomService = new String[customService.size() + 1];
strCustomService[0] = "";
int i = 1;
for (CustomService cs : customService) {
strCustomService[i] = cs.getCustomServiceName();
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, strCustomService);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner SpnCustomService = (Spinner) findViewById(R.id.SpnCustomService);
SpnCustomService.setAdapter(adapter);
}
谢谢!