如何使用Volley将Recyclerview列表发送到服务器 [英] how to send Recyclerview list to Server Using Volley

查看:81
本文介绍了如何使用Volley将Recyclerview列表发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个项目,其中有一个带有3个编辑文本和一个按钮的自定义警报对话框.在按钮上单击它可以将我的数据成功添加到Recyclerview,并且工作正常.

I have created a Project in which i have acustom alertdialog box with 3 edit text and one button. On button Click it add my data to Recyclerview successfully and it's working fine.

现在我想使用volley Post方法将recyclerview数据发布到服务器,任何人都可以帮我解决我该怎么做,我只需要一个如何将recyclerview(我的Recyclerview列表)的数据发送到服务器的想法.我想将阵列中的对象的完整列表发布到服务器.

Now i want to post the recyclerview data to server using volley Post method can any one help me out how can i do it i just need a idea how to send data of recyclerview(list of my Recyclerview) to server. I want to Post full list of objects in array to server.

应该向我发送什么参数,以便成功将recyclerview数据发布到我的服务器.

what should i send to my parameters so that i Successful post the recyclerview data to my server.

我几乎到达那里了,但是我希望所有对象都在同一阵列列表数据中,但是我得到了带有不同对象的不同数组列表(需要一个数组列表中的所有对象)

I have Reached Almost there but i want all objects in my same ARRAY LIST DATA But i am getting Different Array List with different object(need All object in one Array list)

需要类似的输出

 [{
    "movie_name":"trter",
    "movies_Add":"hgjhj90",
    "movie_no":"8787878787"
    }
    {
    "movie_name":"trter",
    "movies_Add":"hgjhj90",
    "movie_no":"8787878787"
    }
    {
    "movie_name":"trter",
    "movies_Add":"hgjhj90",
    "movie_no":"8787878787"
    }
    ]

的代码

 JSONArray movieArray = new JSONArray();
                for (int i = 0; i <= movieList.size(); i++) {
                    JSONObject movieObject = new JSONObject();
                    try {
                        movieObject.put("movie_name", "" + member_name);
                        movieObject.put("movies_Add", "" + member_adds);
                        movieObject.put("movie_no", "" + member_contacts);
                        movieArray.put(movieObject);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                String jsonStr = movieArray.toString();

                Log.i("jsonobj12", String.valueOf(movieArray));
                Log.i("jsonobj123", String.valueOf(movieList1.size()));

日志数据

2020-02-14 09:49:54.283 17587-17587/com.example.raid I/jsonobj12: [{"movie_name":"trter","movies_Add":"hgjhj90","movie_no":"8787878787"}]
2020-02-14 09:49:54.283 17587-17587/com.example.raid I/jsonobj123: 1
2020-02-14 09:50:03.381 17587-17587/com.example.raid I/jsonobj12: [{"movie_name":"tertre","movies_Add":"hgvjnbk99090","movie_no":"7687687868"}]
2020-02-14 09:50:03.381 17587-17587/com.example.raid I/jsonobj123: 2

推荐答案

我想指出的是您的代码中存在一些问题,也许其中一个正在解决您的问题.很难确定真正的问题,因为您没有提供足够的信息:

There are a few problems in your code I want to point out, maybe one of is fixing your problem. Identifying the real problem is hard, because you did not provide enough information:

  1. 此循环for (int i = 0; i <= movieList.size(); i++) {经常迭代一次.假设您的movieList具有3个元素,循环将为(0,1,2,3)中的每个i进行迭代,但是您的列表仅具有索引(0,1,2),因为数组/列表以索引0开头.应该在这里使用i < movieList.size().
  2. 确定要添加正确的项目到movieObject吗? movieObject.put("movie_name", "" + member_name);使用变量 member_name ,该变量不会在循环中更新,您可能需要使用movieList.get(i).member_name或类似的变量(请提供详细信息movieList的外观).以下两行同样适用
  3. 在日志中使用movieList1,但是在循环中使用movieList,确定两个列表都相同吗?
  1. This loop for (int i = 0; i <= movieList.size(); i++) { iterates one time too often. Let's say your movieList has 3 elements, your loop will iterate for each i in (0,1,2,3) but your list only has the indices (0,1,2) as Arrays/Lists start with index 0. So you should use i < movieList.size() here.
  2. Are you sure you are adding the right items to your movieObject? movieObject.put("movie_name", "" + member_name); uses the variable member_name which is not updated within your loop, you probably need to use movieList.get(i).member_name or similar (please provide more information what exactly the movieList looks like). Same applies for the following two lines
  3. In your log you use movieList1 but in your loop you use movieList are you sure both lists are the same?

这篇关于如何使用Volley将Recyclerview列表发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆