Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i need help to fix this bug, i wanna change the listview data if the string is change
here is my code
Java
private void absensi() {
        sharedPreferences = getSharedPreferences("user_details", MODE_PRIVATE);
        String nik_baru = sharedPreferences.getString(KEY_NIK ,null);

        String awal = tanggalawal.getText().toString().trim();
        String akhir = tanggalakhir.getText().toString().trim();

        pDialog = new ProgressDialog(kehadiran.this);
        showDialog();
        pDialog.setContentView(R.layout.progress_dialog);
        pDialog.getWindow().setBackgroundDrawableResource(
                android.R.color.transparent
        );

        StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://example/rest_server/api/absensi/index?shift_day="+ awal +"&shift_day_2=" + akhir + "&badgenumber=" + nik_baru,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {
                            JSONObject obj = new JSONObject(response);
                            final JSONArray movieArray = obj.getJSONArray("data");
                            for (int i = 0; i < movieArray.length(); i++) {
                                final JSONObject movieObject = movieArray.getJSONObject(i);
                                final keteranganmodel movieItem = new keteranganmodel(
                                        movieObject.getString("shift_day"),
                                        movieObject.getString("F1"),
                                        movieObject.getString("depo_f1"),
                                        movieObject.getString("F4"),
                                        movieObject.getString("depo_f4"),
                                        movieObject.getString("ket_absensi"),
                                        movieObject.getString("name"));
                                movieItemList.add(movieItem);
                                hideDialog();

                                final ListViewAdapter adapter = new ListViewAdapter(movieItemList, getApplicationContext());
                                list.setAdapter(adapter);
                                Collections.reverse(movieItemList);

                                adapter.notifyDataSetChanged();

                                searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                                    @Override
                                    public boolean onQueryTextChange(String nextText) {
                                        adapter.getFilter().filter(nextText);
                                        return false;
                                    }

                                    @Override
                                    public boolean onQueryTextSubmit(String query) {
                                        return false;
                                    }
                                });
                            }


                            } catch(JSONException e){
                                e.printStackTrace();

                            }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(), "Maaf, anda belum pernah absen", Toast.LENGTH_SHORT).show();
                    }
                });


        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }


What I have tried:

in these code...
example:
2020-11-10 s/d 2020-11-15
the out put is
2020-11-10
2020-11-11
2020-11-12
2020-11-13
2020-11-14
2020-11-15

but the output when i change the string is
2020-11-10
2020-11-11
2020-11-12
2020-11-13
2020-11-14
2020-11-15
2020-11-10
2020-11-11
2020-11-12
2020-11-13
2020-11-14
2020-11-15
Posted
Updated 8-Nov-20 22:56pm
Comments
wseng 7-Nov-20 11:11am    
you mean you get duplicate data?
Komang Putra 8-Nov-20 9:06am    
yes, thah's right
wseng 11-Nov-20 4:55am    
check Richard's answer.

1 solution

Each time your code executes, you're adding items to movieItemList. But you never clear this list, and you never remove items from it. You'll just keep adding the results of the current query to the results of all previous queries.

Try clearing the list before your for loop.
 
Share this answer
 

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