如何在addOnItemTouchListener中显示JsonObject

时间:2018-01-30 23:08:00

标签: java android json android-recyclerview android-volley

我想在Recyclerview中点击项目时显示信息和文件对象我正在使用排球和JsonObject请求,但无法显示信息和文件。当我使用toast zakeran_any_madah 显示不清楚时,如何解决我的问题并显示信息和文件的正确位置,还有其他方法吗?

这是我的代码

final JsonObjectRequest jsonObjectr = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            res = String.valueOf(response);
            Log.d("reres", res);
            datajson = response;


            try {
                JSONArray jsonArray = response.getJSONArray("list");
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                    int id = jsonObject.getInt("id");
                    int id_category = jsonObject.getInt("id_category");
                    int id_speaker = jsonObject.getInt("id_speaker");
                    String name = jsonObject.getString("name");
                    String image = jsonObject.getString("image");
                    String category_name = jsonObject.getString("category_name");
                    String speaker_name = jsonObject.getString("speaker_name");
                    JSONArray ja = jsonObject.getJSONArray("files");
                    for (int j = 0; j < ja.length(); j++) {

                        JSONObject jo = (JSONObject) ja.get(j);
                        file = jo.getString("file");
                        info = jo.getString("info");
                        Item_zakerin_any itemzakeran = new Item_zakerin_any(id, id_category, name, id_speaker, image, speaker_name, category_name, info, file);
                        list_zakeran_any.add(itemzakeran);

                    }


                }
                az = new adapter_zakeran_any(mcontext, list_zakeran_any);

                rv.setAdapter(az);
                hidepDialog();


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

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {




            hidepDialog();
        }
    });


    jsonObjectr.setRetryPolicy(new DefaultRetryPolicy(15000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    MySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectr);



    rv.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {

        GestureDetector gestureDetector = new GestureDetector(zakeran_any_madah.this, new GestureDetector.SimpleOnGestureListener() {

            @Override public boolean onSingleTapUp(MotionEvent motionEvent) {

                return true;
            }

        });
        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent motionEvent) {

            ChildView =rv.findChildViewUnder(motionEvent.getX(),motionEvent.getY());
            if (ChildView !=null && gestureDetector.onTouchEvent(motionEvent)){
                GetItemPosition =rv.getChildAdapterPosition(ChildView);
                Toast.makeText(zakeran_any_madah.this, ""+ list_zakeran_any.get(GetItemPosition), Toast.LENGTH_LONG).show();




            }



            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {

        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

        }
    });

0 个答案:

没有答案