我的Android应用程序中有两个微调器。一个用于选择链,另一个用于选择商店。我想向两个微调器添加项目。第二个微调器的项依赖于第一个微调器,即 store 的项应该依赖于所选的链项。我试过同样但商店的商品是空的。请帮帮我 - 这是我试过的代码:
private class ChainDownloadTask extends AsyncTask<Void, Void, ArrayList<Chain>> {
@Override
protected void onPreExecute() {
mProgressDialog = ProgressDialog.show(SelectStoreActivity.this, null, "Loading Chains...");
}
@Override
protected ArrayList<Chain> doInBackground(Void... arg0) {
// call web method to get all chains
CallSoap cs = new CallSoap();
ArrayList<Chain> chainList = cs.getAllChains();
return chainList;
}
@Override
protected void onPostExecute(ArrayList<Chain> result) {
mArrayListChains = result;
loadChainSpinner();
new StoresDownloadTask().execute();
}
}
private class StoresDownloadTask extends AsyncTask<Void, Void, ArrayList<Store>> {
@Override
protected void onPreExecute() {
mProgressDialog.setMessage("Loading Stores...");
}
@Override
protected ArrayList<Store> doInBackground(Void... arg0) {
// call web method to get all chains
CallSoap cs = new CallSoap();
ArrayList<Store> chainList = cs.getAllStores();
return chainList;
}
@Override
protected void onPostExecute(ArrayList<Store> result) {
mArrayListStores = result;
loadStoreSpinner(mArrayListChains.get(0).getId());
mProgressDialog.dismiss();
}
}
private void loadChainSpinner() {
ArrayList<String> chainNameList = new ArrayList<String>();
for (Chain temp : mArrayListChains) {
chainNameList.add(temp.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(SelectStoreActivity.this, android.R.layout.simple_spinner_item, chainNameList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinnerChain.setAdapter(adapter);
}
private void loadStoreSpinner(int chainId) {
ArrayList<Store> storeList = new ArrayList<Store>();
ArrayList<String> storeNameList = new ArrayList<String>();
for (Store store : mArrayListStores) {
if((""+chainId).equals(store.getChainID())){
storeList.add(store);
storeNameList.add(store.getFld_str_Name());
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(SelectStoreActivity.this, android.R.layout.simple_spinner_item, storeNameList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinnerStores.setAdapter(adapter);
}
`
答案 0 :(得分:0)
检查以下代码
for (int i = 0; i < Counter; i++) {
strPromoterNames[i] = promoterDetailsResponse.Sub_promoters.get(i).SubpromoterName;
}
ArrayAdapter<String> adapterPromoterDetails = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, strPromoterNames);
adapterPromoterDetails.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerPromoterDetails.setAdapter(adapterPromoterDetails);