GET yöntemi yanlış değer döndürür

oy
0

Ben doldurmak çalışıyorum observersIDssonra ArrayList benim parametre olarak koydu TicketModelnesnenin setter ticket.setObserverIDs(observersIDs).

Ben şöyle ArrayList içeriği görüntülemek ediyorum DisplayArrayList(observersIDs)ben ayarlayıcı diyoruz hemen önce. Ve fortunalely liste istediğim değer (ler) içeriyor.

Ancak, en kısa sürede (döngünün dışında) benim ListView doldurma sonra getter diyoruz ve içeriğini görüntülemek gibi ArrayList boştur. Ben her sonra benim ArrayList temizleyerek ediyorum çünkü eminim TicketModels.add(ticket);(O talimat gerekiyor), ama bu ArrayList gösteren değilim çünkü sens yapmaz, ama yerine TicketModek nesnenin toplama maddesinin arıyorum hangi zaten dolduruldu.

İşte benim sınıf var:

public class ListTickets extends Fragment {

    private ArrayList<TicketModel> TicketModels;
    private ArrayList<String> observersIDs;
    private ListView listView;
    private static TicketAdapter adapter;

    private RequestQueue queue;
    private String motifAttente;
    private String titreTicket, slaTicket, urgenceTicket, idTicket, demandeurTicket,
            categorieTicket, etatTicket, dateDebutTicket, statutTicket,
            dateEchanceTicket, dateClotureTicket, dateResolutionTicket, descriptionTicket, lieuTicket;

    public static Handler handlerticket;
    boolean ticketEnretard;


    public ListTickets() {
        handlerticket = new HandlerTicket();
        Log.d(INITIALIZATION,J'ai intialisé le handler en cours !);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.list_tickets, container, false);

        initView(view);    
        registerForContextMenu(listView);
        getTicketsHTTP();

        return view;
    }



    private void initView(View view) {
        TicketModels = new ArrayList<>();
        observersIDs = new ArrayList<>();
        queue = Volley.newRequestQueue(getActivity());
        listView = view.findViewById(R.id.list);
    }

    private void getTicketsHTTP() {
        String url = Constants.GLPI_URL+search/Ticket;

        int maxRange = range-1;
        List<KeyValuePair> params = new ArrayList<>();
        //TECHNICIEN = IDUSER
        params.add(new KeyValuePair(criteria[0][field],5));
        params.add(new KeyValuePair(criteria[0][searchtype],equals));
        params.add(new KeyValuePair(criteria[0][value],idUser));
        //AND STATUT EST EN COURS (ATTIRIBUE)
        params.add(new KeyValuePair(criteria[1][link],AND));
        params.add(new KeyValuePair(criteria[1][field],12));
        params.add(new KeyValuePair(criteria[1][searchtype],equals));
        params.add(new KeyValuePair(criteria[1][value],2));
        //OU TECHNICIEN = IDUSER
        params.add(new KeyValuePair(criteria[2][link],OR));
        params.add(new KeyValuePair(criteria[2][field],5));
        params.add(new KeyValuePair(criteria[2][searchtype],equals));
        params.add(new KeyValuePair(criteria[2][value],idUser));
        //AND STATUT EST EN COURS (PLANIFIE)
        params.add(new KeyValuePair(criteria[3][link],AND));
        params.add(new KeyValuePair(criteria[3][field],12));
        params.add(new KeyValuePair(criteria[3][searchtype],equals));
        params.add(new KeyValuePair(criteria[3][value],3));      
       //AFFICHAGE
        params.add(new KeyValuePair(forcedisplay[0],4));
        params.add(new KeyValuePair(forcedisplay[1],10));
        params.add(new KeyValuePair(forcedisplay[2],7));
        params.add(new KeyValuePair(forcedisplay[3],12));
        params.add(new KeyValuePair(forcedisplay[4],15));
        params.add(new KeyValuePair(forcedisplay[5],30));
        params.add(new KeyValuePair(forcedisplay[6],18));
        params.add(new KeyValuePair(forcedisplay[7],21));
        params.add(new KeyValuePair(forcedisplay[8],83));
        params.add(new KeyValuePair(forcedisplay[9],82));
        params.add(new KeyValuePair(forcedisplay[10],16));
        params.add(new KeyValuePair(forcedisplay[11],2));
        params.add(new KeyValuePair(forcedisplay[12],17));
        params.add(new KeyValuePair(forcedisplay[13],66));
        //ORDRE ET RANGE
        params.add(new KeyValuePair(sort,15));
        params.add(new KeyValuePair(order,DESC));
        params.add(new KeyValuePair(range,0-+maxRange+));

        final JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, generateUrl(url, params), null,
                new Response.Listener<JSONObject>()
                {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {

                            JSONArray Jdata = response.getJSONArray(data);
                            for (int i=0; i < Jdata.length(); i++) {
                                try {
                                    JSONObject oneTicket = Jdata.getJSONObject(i);

                                    titreTicket = oneTicket.getString(1);
                                    slaTicket = oneTicket.getString(30);
                                    dateDebutTicket = oneTicket.getString(15);
                                    urgenceTicket = oneTicket.getString(10);
                                    statutTicket = oneTicket.getString(12);
                                    idTicket = oneTicket.getString(2);

                                    demandeurTicket = oneTicket.getString(4);
                                    categorieTicket = oneTicket.getString(7);
                                    etatTicket = oneTicket.getString(12);
                                    dateEchanceTicket = oneTicket.getString(18);
                                    descriptionTicket = oneTicket.getString(21);

                                    lieuTicket = oneTicket.getString(83);
                                    dateClotureTicket = oneTicket.getString(16);
                                    dateResolutionTicket = oneTicket.getString(17);
                                    ticketEnretard = getBooleanFromSt(oneTicket.getString(82));

                                    observateur = oneTicket.getString(66);

                                    observersIDs.clear();
                                    try {
                                        JSONArray JObs = oneTicket.getJSONArray(66);
                                        Log.d(JSONARRAY OBS N°+i+ (+titreTicket+),Observer converted to JSONArray !);
                                        for (int j=0; j < JObs.length(); j++) {
                                            try {
                                                String oneObservateur = JObs.getString(j);
                                                observersIDs.add(oneObservateur);
                                            } catch (JSONException e) {
                                                Log.e(Error Observateur , e.getMessage());
                                            }
                                        }
                                    } catch (JSONException e) {
                                        Log.e(JSONARRAY OBSERVER (+titreTicket+),Observer cannot be converted to JSONArray...);
                                        observersIDs.add(observateur);
                                    }

                                } catch (JSONException e) {
                                    Log.e(Nb of data: +Jdata.length()+ || +Error JSONArray at +i+ : , e.getMessage());
                                }

                                /* ---------  Creating a TicketModel object  --------- */

                                TicketModel ticket = new TicketModel(titreTicket, slaTicket, dateDebutTicket,
                                        calculTempsRestant(dateEchanceTicket), idTicket, statutTicket);

                                ticket.setUrgenceTicket(urgenceText(urgenceTicket));
                                ticket.setTicketEnRetard(Boolean.parseBoolean(String.valueOf(ticketEnretard)));
                                ticket.setDescription(descriptionTicket);
                                ticket.setDemandeurID(demandeurTicket);

                                System.out.println(____ Testing Obs ArrayList during Model creation ____);

                                DisplayArrayList(observersIDs); //THE CORRECT ARRAYLIST IS DISPLAYED

                                ticket.setObserverIDs(observersIDs); //I SET IT JUST AFTER SINCE IT'S ALWAYS THE CORRECT VALUE

                                TicketModels.add(ticket);

                                observersIDs.clear();

                                /* ---------  Creating a TicketModel object  --------- */

                            }


                            if (getActivity() != null){
                                adapter = new TicketAdapter(TicketModels,getActivity());
                            }
                            else{
                                Log.e(ERROR, An Error was about to occur);
                            }


                            listView.setAdapter(adapter);


                            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


                                    TicketModel TicketModel = TicketModels.get(position);


                                    DisplayArrayList(TicketModel.getObserverIDs()); //I GET A EMPTY ARRAYLIST


                                    startActivity(i);

                                }
                            });


                        } catch (JSONException e) {
                            Log.e(malkach,e.getMessage());
                        }


                    }
                },
                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e(Error.Response!, error.toString());
                    }

                }
        ){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                params.put(App-Token,Constants.App_Token);
                params.put(Session-Token,session_token);
                return params;
            }

        };

        // add it to the RequestQueue
        queue.add(getRequest);

    }


    private void DisplayArrayList(ArrayList list) {
        System.out.println(\n --- ArrayList --- \n);
        for (int i = 0; i < list.size(); i++){
            String oneObs = (String)list.get(i);
            System.out.println(oneObs);
        }
    }

}

Ve işte benim TicketModel sınıfı var:

public class TicketModel {
    private String titreTicket;
    private String slaTicket;
    private String DateTicket;
    private String UrgenceTicket;
    private boolean ticketEnRetard;
    private String TempsRestantTicket;
    private String idTicket;
    private String Statut;
    private String TempsResolution;
    private String TempsRetard;
    private String description;
    private String demandeurID;
    private ArrayList<String> observerIDsss;


    public TicketModel(String titreTicket, String slaTicket, String dateTicket, String tempsRestantTicket, String idticket, String statut) {
        this.titreTicket = titreTicket;
        this.slaTicket = slaTicket;
        DateTicket = dateTicket;
        TempsRestantTicket = tempsRestantTicket;
        idTicket = idticket;
        Statut = statut;
    }

    public String getTitreTicket() {
        return titreTicket;
    }

    public String getSlaTicket() {
        return slaTicket;
    }

    public String getDateTicket() {
        return DateTicket;
    }

    public String getUrgenceTicket() {
        return UrgenceTicket;
    }

    public void setUrgenceTicket(String urgenceTicket) {
        UrgenceTicket = urgenceTicket;
    }

    public void setTempsRestantTicket(String tempsRestantTicket) { TempsRestantTicket = tempsRestantTicket; }

    public String getTempsRestantTicket() {
        return TempsRestantTicket;
    }

    public boolean isTicketEnRetard() {
        return ticketEnRetard;
    }

    public void setTicketEnRetard(boolean ticketEnRetard) {
        this.ticketEnRetard = ticketEnRetard;
    }

    public String getIdTicket() { return idTicket; }

    public String getStatut() { return Statut; }

    public String getTempsResolution() {
        return TempsResolution;
    }

    public void setTempsResolution(String tempsResolution) {
        TempsResolution = tempsResolution;
    }

    public String getTempsRetard() {
        return TempsRetard;
    }

    public void setTempsRetard(String tempsRetard) {
        TempsRetard = tempsRetard;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setDemandeurID(String demandeurID) {
        this.demandeurID = demandeurID;
    }

    public String getDemandeurID() {
        return demandeurID;
    }


    public void setObserverIDs(ArrayList<String> observerIDs) {
        this.observerIDsss = observerIDs;
    }

    public ArrayList<String> getObserverIDs() {
        return observerIDsss;
    }



}

toplama maddesinin çağrılırken ben doğru değerleri alamıyorum neden birisi bana açıklayabilir?

Oluştur 08/11/2018 saat 11:24
kaynak kullanıcı
Diğer dillerde...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more