JSON列表将两个Json FIles结合在一起Android

时间:2015-05-01 15:47:00

标签: android json listview

我正在创建一个具有不同json文件的可更改json信息的项目,问题是当我点击第一个单选按钮时效果很好但是当我点击第二个时,列表将完美显示但是它是从两个文件中解析出来的。这是我的代码:

    public void showFoodItems(String shit)
{

    movieList.clear();
    adapter.notifyDataSetChanged();
    // Creating volley request obj
    JsonArrayRequest movieReq = new JsonArrayRequest(
            "http://users.abdullahadhaim.com/users/WebServiceResturant.asmx/getFoodItems?categoryName="
                    + shit, new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, response.toString());

                    // Parsing json
                    for (int i = 0; i < response.length(); i++) {
                        try {

                            JSONObject obj = response.getJSONObject(i);
                            Movie movie = new Movie();
                            movie.setTitle(obj.getString("title"));
                            movie.setThumbnailUrl(obj.getString("image"));
                            movie.setPrice(((Number) obj.get("price"))
                                    .doubleValue());
                            movie.setOrderNum(obj.getInt("categoryno"));
                            movie.setCategory(obj.getString("category"));

                            // adding movie to movies array
                            movieList.add(movie);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    // notifying list adapter about data changes
                    // so that it renders the list view with updated data
                    adapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());

                }
            });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(movieReq);

    /* @#@#@#@# JSON Items ListView END @#@#@#@# */

}

这就是radioButton onCLick的方法:

rd1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
        /// movieList.clear();
        //  adapter.notifyDataSetChanged();
        //  listView.setAdapter(adapter);

            showFoodItems("Starter");

        }
    });


    rd2.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
        //  movieList.clear();
        //  //adapter.notifyDataSetChanged();
            //listView.setAdapter(adapter);

            showFoodItems("Desserts");

        }
    });

0 个答案:

没有答案