单击第一个微调器之后如何设置Secound微调器?

时间:2018-06-29 06:18:03

标签: android-studio

    Spnnerdata(urdata);
    city.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

           String data=  city.getItemAtPosition(city.getSelectedItemPosition()).toString();
            long p = city.getItemIdAtPosition(position);

           if (p == 1){
               langugae.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                   @Override
                   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                   }
               });

           }

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {


        }
    });



}



    public void Spnnerdata (String urdata) {

//             StringRequest stringRequest =新的StringRequest(Request.Method.POST,urdata,新的Response.Listener(){                 @Override                 public void onResponse(String response){                     //预期回应=“”                     // [{{“ cat_id”:“ 1”,“ type”:“英语”,“ cat_name”:“ himanshu”,“新闻”:“印度斯坦”},                     // {“ cat_id”:“ 2”,“ type”:“英语”,“ cat_name”:“ html”,“新闻”:“印度时报”}]

                // response = "
                //                         LucknowTimes of IndiaHindiUnnaoThe EnduEnglish
                //
                //                                         ;

                System.out.println(response);
                try {
                    JSONArray jsonArr = new JSONArray(response);
                    for (int i = 0; i < jsonArr.length(); i++) {
                        JSONObject jsonObject = jsonArr.getJSONObject(i);
                        //   Log.d("Items : ", jsonObject.getString("xxx"));
                        String data = jsonObject.getString("cat_name");

                        String langg = jsonObject.getString("type");
                         String newspaer=jsonObject.getString("news");

                        lang.add(langg);
                        citylist.add((data));
                        newsdata.add(newspaer);

                    }
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(Category.this, android.R.layout.simple_list_item_1, citylist);
                    adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                    city.setAdapter(adapter);

                    ArrayAdapter<String> languge = new ArrayAdapter<String>(Category.this, android.R.layout.simple_list_item_1,lang);
                    langugae.setAdapter(languge);

                    ArrayAdapter<String> newss = new ArrayAdapter<String>(Category.this, android.R.layout.simple_list_item_1,newsdata);
                    news.setAdapter(newss);
                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }


        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.getMessage();
            }
        });
        requestQueue.add(stringRequest);
    }

0 个答案:

没有答案