从WebService获取微调器数据

时间:2018-06-19 06:31:26

标签: android web-services android-spinner

我创建了一个Android应用程序,我正在调用具有属性名称和属性值的webservice,我想在Spinner中显示属性值,并在TextView中显示属性名称。如果属性值为2,则存储两个arrylist。如果两个列表中的属性名称相同,则只存储一个列表。如果属性名称更改,则添加新的arraylist。以下是我的代码

//call webservice for product attribute 

    private class getCategoryProductAttribute extends AsyncTask<String, String, String> {
            ProgressDialog pdLoading = new ProgressDialog(ProductDescriptionActivity.this);
            StringBuilder result = null;
            String response;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pdLoading.setMessage("Loding..");
                pdLoading.setCancelable(false);
                pdLoading.show();
            }

            @Override
            protected String doInBackground(String... strings) {
                if (pref.isLoggedIn() == true) {
                    constant_pref.getPrefData();
                } else {
                    constant_pref.UserName = "remplastic@admin";
                    constant_pref.Password = "remplastic@admin";
                    constant_pref.AppVersion = getVersionInfo();
                    constant_pref.DataVersion = "1.0";
                }
                Webservice addressService = new Webservice();
                String query = "<value><user_name>" + constant_pref.UserName + "</user_name>" +
                        "<user_password>" + constant_pref.Password + "</user_password>" +
                        "<product_id>" + Product_Id + "</product_id>" +
                        "<appversion_text>" + constant_pref.AppVersion + "</appversion_text>" +
                        "<dataversion_text>" + constant_pref.DataVersion + "</dataversion_text></value>";
                try {
                    addressService.XmlPostData(ConstantUrl.Product_Attribute_Url, query);
                    result = addressService.getResponse();
                    response = result.toString();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return response;
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                try {
                    if (response.length() > 0) {
                        int code = Integer.parseInt(XMLManualParser.getTagValue(ConstantUrl.TAG_CODE, response));
                        String msg = XMLManualParser.getTagValue("message", response);
                        if (code == 1) {
                            spinnerlist.clear();
                            ArrayList<String> productlist = XMLManualParser.getMultipleTagList(ConstantUrl.TAG_LIST, response);
                            for (int i = 0; i < productlist.size(); ++i) {
                                String responseContent = productlist.get(i);
                                HashMap<String, String> hashMap = new HashMap<String, String>();
                                hashMap.put("attr_name", XMLManualParser.getTagValue(ConstantUrl.attribute_name, responseContent));
                                hashMap.put("attr_value", XMLManualParser.getTagValue(ConstantUrl.attribute_value, responseContent));
                                hashMap.put("attr_dealerprize", XMLManualParser.getTagValue(ConstantUrl.product_dealerprice, responseContent));
                                hashMap.put("attr_retailer_prize", XMLManualParser.getTagValue(ConstantUrl.product_retaillerprice, responseContent));
                                spinnerlist.add(hashMap);
                                if (XMLManualParser.getTagValue(ConstantUrl.attribute_name, responseContent).toLowerCase().equalsIgnoreCase("print")) {

                                }
                            }
                            attribute_adapter.notifyDataSetChanged();
                        } else {
                            Toast.makeText(ProductDescriptionActivity.this, msg, Toast.LENGTH_SHORT).show();
                        }
                        attribute_adapter.notifyDataSetChanged();
                    }
                } catch (Exception e) {

                }
                pdLoading.dismiss();
            }
        }

0 个答案:

没有答案