使用齐射将数据从mysql数据库添加到tableLayout

问题描述

我正尝试如下使用排球将数据添加到tableLayout中

    private void getData() {
    final ArrayList <Detail> drinks = new ArrayList<>();
    final RotatingCircularDotsLoader loader = new RotatingCircularDotsLoader(getActivity(),20,60,ContextCompat.getColor(getActivity(),R.color.red));
    loader.setAnimDuration(3000);
    content.addView(loader);
    StringRequest drinkStringRequest = new StringRequest(Request.Method.GET,AppConfig.URL_DETAILS,new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    JSONObject jsonObject;
                    try{
                        JSONObject drinkObject = new JSONObject(response);
                        JSONArray drinkArray = drinkObject.getJSONArray("data");
                        for(int i=0; i<drinkArray.length();i++){
                            jsonObject = drinkArray.getJSONObject(i);
                            tableRow = LayoutInflater.from(getActivity()).inflate(R.layout.table_item,null,false);
                            //table components
                            id = tableRow.findViewById(R.id.id);
                            name = tableRow.findViewById(R.id.name);
                            ppn = tableRow.findViewById(R.id.ppn);
                            spn = tableRow.findViewById(R.id.spn);
                            email = tableRow.findViewById(R.id.email);
                            idno = tableRow.findViewById(R.id.idNo);
                            btype = tableRow.findViewById(R.id.btype);
                            loc = tableRow.findViewById(R.id.loc);
                            monthly = tableRow.findViewById(R.id.monthly);
                            status = tableRow.findViewById(R.id.status);
                            created = tableRow.findViewById(R.id.created);
                            id.setText(String.valueOf(jsonObject.getInt("id")));
                            name.setText(jsonObject.getString("name"));
                            ppn.setText(jsonObject.getString("primaryphone"));
                            spn.setText(jsonObject.getString("secondaryphone"));
                            email.setText(jsonObject.getString("email"));
                            idno.setText(String.valueOf(jsonObject.getInt("idno")));
                            btype.setText(jsonObject.getString("businesstype"));
                            loc.setText(jsonObject.getString("location"));
                            monthly.setText(jsonObject.getString("monthlyrevenue"));
                            created.setText(jsonObject.getString("reg_date"));
                            status.setText(String.valueOf(jsonObject.getInt("status")));
                            items.addView(tableRow);
                        }
                        content.removeView(loader);

                    }catch (JSONException e){
                        content.removeView(loader);
                        e.printStackTrace();
                    }
                }
            },new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    content.removeView(loader);
                    error.printStackTrace();
                }
            });
    RequestQueue requestQue = Volley.newRequestQueue(getActivity());
    requestQue.add(drinkStringRequest);
}

程序运行没有错误,但是尽管数据库中有正在获取的数据也没有添加行,并且当我调试每个jsonObject值时,我得到了一些信息,即 Log.d(TAG,"onResponse: "+jsonObject.getString("monthlyrevenue"));在控制台中给出了45000,但是行为空。 我该怎么办呢,或者我该如何设法将数据添加到表中?

这是我的json响应

    {"data":[{"id":1,"name":"test","primaryphone":"0712345678","secondaryphone":"0723456789","email":"[email protected]","idno":123456789,"businesstype":"test","location":"test","monthlyrevenue":"45000","regdate":"2020-09-21 11:20:05","updatedate":null,"status":1}]}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)