Click here to Skip to main content
15,867,750 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need help to solve this problem.. i wanna getting last data but it won't take so long

here is my code
Java
private void getNo() {
        pDialog = new ProgressDialog(this);
        showDialog();
        pDialog.setContentView(R.layout.progress_dialog);
        pDialog.getWindow().setBackgroundDrawableResource(
                android.R.color.transparent
        );
        StringRequest stringRequest1 = new StringRequest(Request.Method.GET, "http://example.co.id/rest_server/api/nomor_pengajuan/index_full_day",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response);
                            JSONArray movieArray = obj.getJSONArray("data");

                            for (int i = 0; i < movieArray.length(); i++) {
                                JSONObject movieObject = movieArray.getJSONObject(i);
                                getNo_pengajuan_full nomor = new getNo_pengajuan_full(
                                        movieObject.getInt("no_pengajuan_full_day"));
                                no_pengajuan.add(nomor);

                                getNo_pengajuan_full item = no_pengajuan.get(no_pengajuan.size() - 1);

                                nopengajuan.setText(String.valueOf(item.getNo_pengajuan_full() + 1));
                                hideDialog();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(), "Maaf, ada kesalahan", Toast.LENGTH_SHORT).show();
                    }
                });
        RequestQueue requestQueue1 = Volley.newRequestQueue(this);
        requestQueue1.add(stringRequest1);
    }


in this case i want a pick the last array without loading...
picking data "no_pengajuan_full_day"

What I have tried:

Java
@Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response);

                                JSONObject movieObject = obj.getJSONObject(response);
                                getNo_pengajuan_full nomor = new getNo_pengajuan_full(
                                        movieObject.getInt("no_pengajuan_full_day"));
                                no_pengajuan.add(nomor);

                                getNo_pengajuan_full item = no_pengajuan.get(no_pengajuan.size() - 1);

                                nopengajuan.setText(String.valueOf(item.getNo_pengajuan_full() + 1));
                                hideDialog();


i tried this code but it's not respond
Posted
Comments
David Crow 18-Nov-20 8:23am    
"i wanna getting last data but it won't take so long"

What exactly does this mean? What is a "last data?" Usually when something does not take long, that's a good thing.

"in this case i want a pick the last array without loading.."

Yet you are calling getInt() in the onResponse() method.

Are you trying to parse a JSON file? If so, what does it look like?
Komang Putra 18-Nov-20 9:34am    
yeah... so i want pick a data which in the last index..
but the program must find a last index for so long...
David Crow 18-Nov-20 9:59am    
"the program must find a last index for so long..."

What is this supposed to mean?

JSONArray array = obj.getJSONArray("");
JSONObject data = array.getJSONObject(last_index);
Komang Putra 18-Nov-20 10:28am    
yes, but i just want get last index without loading
David Crow 18-Nov-20 10:35am    
The entire JSON file has already been put in obj. What's your concern?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900