Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

android - Recycler View is Showing Blank Screen after Resuming the activity

Activity called First

This is the activity When calledOnResume Method

   private void loadFrieghtData() {


        progressLoader.startProgress(Frieght_Details.this);

        RequestQueue queue = Volley.newRequestQueue(Frieght_Details.this);

        StringRequest stringRequest = new StringRequest(Request.Method.POST, UrlConstant.FRIEGHT_DETAILS,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            String status = jsonObject.optString("status");
                            if (status.equals("1")){

                                JSONArray jsonArray = jsonObject.getJSONArray("data");

                                for (int i =0 ; i< jsonArray.length(); i++){

                                    JSONObject jsonObject1 = jsonArray.getJSONObject(i);


                                    dialogPOJO  leftDashboardPOJO = new dialogPOJO(jsonObject1.optString("id"),
                                            jsonObject1.optString("date"), jsonObject1.optString("credit"),
                                            jsonObject1.optString("confirm_status"));

                                    leftDashboardPOJOSList.add(leftDashboardPOJO);

                                }

                                progressLoader.dismissProgress(Frieght_Details.this);
                                millWiseReportRecyclerView.setAdapter(FrieghtAdapterPOJO);
                                FrieghtAdapterPOJO.notifyDataSetChanged();

                                System.out.println("SOMETHING DATA " + response.toString());

                            }else {

                                progressLoader.dismissProgress(Frieght_Details.this);
                                Toast.makeText(Frieght_Details.this, "Something Went Wrong", Toast.LENGTH_SHORT).show();

                            }

                        }catch (JSONException e){
                            progressLoader.dismissProgress(Frieght_Details.this);
                            System.out.println("paramsparamsparams===" + e.toString());

                            Toast.makeText(Frieght_Details.this, e.toString(), Toast.LENGTH_SHORT).show();

                        }

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

                progressLoader.dismissProgress(Frieght_Details.this);
                System.out.println("paramsparamsparams===" + error.toString());

                Toast.makeText(Frieght_Details.this, error.toString(), Toast.LENGTH_SHORT).show();
            }
        }){
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                {
                  /*  params.put("user_id", prefManager.getGSTstate());
                    params.put("godown_id", prefManager.getGodownlocation()); */

                    params.put("godown_id", "3");
                    params.put("user_id", "dddd");
                    params.put("vehicle", "2");


                }



                System.out.println("paramsparamsparams===" + params.toString());
                return params;
            }

        };


        stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 8,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


        queue.add(stringRequest);


    }

This is my Main Method Code

public class FreightAdapter extends RecyclerView.Adapter<FreightAdapter.ViewHolder> {

    private List<dialogPOJO> list_data;
    private Frieght_Details context;
    private PrefManager prefManager;

    public FreightAdapter(List<dialogPOJO> list_data, Frieght_Details context) {
        this.list_data = list_data;
        this.context = context;
        prefManager = new PrefManager(context);
    }

    @Override
    public FreightAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.frieght_wiseadapterlayout,parent,false);
        return new FreightAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(FreightAdapter.ViewHolder holder, int position) {
        final dialogPOJO  lenaDenaPOJO = list_data.get(position);


        if (position %2 == 1){

            holder.linearLayout_data.setBackgroundColor(context.getResources().getColor(R.color.white));

        }else {

            holder.linearLayout_data.setBackgroundColor(context.getResources().getColor(R.color.colorGrey));


        }

        String countString = lenaDenaPOJO.getCount();


        holder.ordernumber.setText( countString );

        holder.ordernumber1.setText( lenaDenaPOJO.getKey());

        String truck_id = lenaDenaPOJO.getReports();
        String vehicle_status = lenaDenaPOJO.getVehicleStatus();

        System.out.println("VEHICLE_VALE " + vehicle_status + " " + truck_id + " " + countString);

        holder.frieght.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                context.callDialogMethod(countString);

            }
        });


        holder.actionOK.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                context.CallOkStatus(vehicle_status, countString, truck_id);

            }
        });
    }

    @Override
    public int getItemCount() {
        return list_data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView ordernumber, ordernumber1, frieght, actionOK;
        private Button view_Reports;
        private LinearLayout linearLayout_data;

        public ViewHolder(View itemView) {
            super(itemView);

            ordernumber = itemView.findViewById(R.id.pro_name);
            ordernumber1 = itemView.findViewById(R.id.frieght);
            frieght = itemView.findViewById(R.id.total_qty);
            actionOK = itemView.findViewById(R.id.actionOK);

            linearLayout_data = itemView.findViewById(R.id.linearLayout_data);


        }
    }
}

Here are logs

I/System.out: SOMETHING DATA {"status":1,"data":[{"id":2876,"credit":1500,"confirm_status":1,"date":"01-01-2021"},{"id":2919,"credit":1900,"confirm_status":1,"date":"02-01-2021"},{"id":2933,"credit":2050,"confirm_status":1,"date":"04-01-2021"},{"id":2964,"credit":3500,"confirm_status":1,"date":"05-01-2021"},{"id":3004,"credit":2450,"confirm_status":1,"date":"06-01-2021"}

And This is my Adapter Code I can't understand What is wrong in this.

Please Help me in this case

I have added image for more details,

When I call Activity First Time it works Perfectly But If call onResume method then There is no data added on Recycler view I can't understand what get wrong in my code

question from:https://stackoverflow.com/questions/65842572/recycler-view-is-showing-blank-screen-after-resuming-the-activity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...