1

我的 android 应用程序中有两个微调器。一个用于选择连锁店,另一个用于选择商店。我想向两个微调器添加项目。第二个微调器的项目取决于第一个微调器,即商店的项目应该取决于所选的连锁项目。我也试过了,但商店里的东西是空的。请帮助我-这是我尝试过的代码:

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);
    }

在此处输入图像描述`

4

1 回答 1

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);
于 2013-08-07T09:18:34.030 回答