Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a problem when i create a list view using 2 url, here is my code

Java
private void loadPlayer() {
       String jabatan = txt_jabatan_struktur.getText().toString().trim();

       System.out.println("test 111 = " + jabatan);

       StringRequest stringRequest1 = new StringRequest(Request.Method.GET, "http://example.co.id/rest_server/master/team/index?jabatan_struktur=" + jabatan,
               new Response.Listener<String>() {
                   @Override
                   public void onResponse(String response) {
                       try {
                           final JSONObject object = new JSONObject(response);
                           JSONArray movieArray = object.getJSONArray("data");

                           JSONObject movieObject2 = null;
                           for (int i = 0; i < movieArray.length(); i++) {

                               movieObject2 = movieArray.getJSONObject(i);

                               rekapabsensiclass movieItem = new rekapabsensiclass(
                                       movieObject2.getString("nik_baru"),
                                       movieObject2.getString("nama_karyawan_struktur"),
                                       movieObject2.getString("lokasi_struktur"));

this code i used for getting data for first url

Java
String nik_baru = movieObject2.getString("nik_baru");
                                System.out.println("Test nik baru =" + nik_baru);

then i save a data called nik_baru as a string

Java
Calendar calendar = Calendar.getInstance();
                                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
                                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                String firstdate = simpleDateFormat.format(calendar.getTime());
                                System.out.println("Test tanggal 1 =" + firstdate);

                                SimpleDateFormat sdf2 = new SimpleDateFormat( "yyyy-MM-dd" );
                                String lastdate = sdf2.format(new Date());
                                System.out.println("Test tanggal 2 =" + lastdate);

                                StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://example.co.id/rest_server/api/absensi/index?shift_day="+ firstdate +"&shift_day_2="+ lastdate +"&badgenumber=" + nik_baru,
                                        new Response.Listener<String>() {
                                            @Override
                                            public void onResponse(String response) {
                                                try {
                                                    JSONObject obj = new JSONObject(response);
                                                    JSONArray movieArray = obj.getJSONArray("data");
                                                    int number = 0;
                                                    int number1 = 0;
                                                    int number2 = 0;
                                                    int number3 = 0;

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

                                                        JSONObject movieObject = movieArray.getJSONObject(i);

                                                        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"));


after that i used string nik_baru for processing data

Java
if (movieObject.getString("ket_absensi").contains("TL"))
                                                            number1++; {
                                                            telat.setText(String.valueOf(number1));
                                                        }
                                                        if (movieObject.getString("ket_absensi").contains("AL"))
                                                            number2++; {
                                                            alfa.setText(String.valueOf(number2));
                                                        }
                                                        if (movieObject.getString("ket_absensi").contains("SA"))
                                                            number3++; {
                                                            sakit.setText(String.valueOf(number3));
                                                        }
                                                        if (movieObject.getString("ket_absensi").contains("HD"))
                                                            number++;  {
                                                            hadir.setText(String.valueOf(number));
                                                        }

this is for counting data

Java
public static class ListViewAdapterTeam extends ArrayAdapter<rekapabsensiclass> {

        public List<rekapabsensiclass> team;
        public static TextView telat, alfa, sakit, hadir;
        private Context context;


        public ListViewAdapterTeam(List<rekapabsensiclass> team, Context context) {
            super(context, R.layout.list_item_rekapabsensi, team);
            this.team = team;
            this.context = context;

        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            LayoutInflater inflater = LayoutInflater.from(context);

            View listViewItem = inflater.inflate(R.layout.list_item_rekapabsensi, null, true);

            TextView nikbaruteam = listViewItem.findViewById(R.id.nik);
            TextView nama = listViewItem.findViewById(R.id.nama);
            telat = listViewItem.findViewById(R.id.telat);
            alfa = listViewItem.findViewById(R.id.alfa);
            sakit = listViewItem.findViewById(R.id.sakit);
            hadir = listViewItem.findViewById(R.id.hadir);

            rekapabsensiclass movieItem = getItem(position);

            nikbaruteam.setText(movieItem.getNik_baru());
            nama.setText(movieItem.getNama_karyawan_struktur());


            return listViewItem;

        }
    }

}


and this is a code for create a listviewadapter

What I have tried:

- String nik_baru/firstdate, lastdate already processing
- counting data always keep zero in list view
Posted
Comments
David Crow 20-Nov-20 22:42pm    
What exactly is the problem? The title of this post says one thing, but the code you've provided says something else. In fact, most of the code you've shown can probably be removed as it is not relevant.

You're pulling data from two JSON files, and want to add pieces of each to a ListView. Is that anywhere near correct?
Komang Putra 20-Nov-20 22:44pm    
yes, that's right
the problem is the count data always keep zero
David Crow 21-Nov-20 20:35pm    
So have you bothered to step through the code using the debugger to find out WHY?
Komang Putra 22-Nov-20 20:39pm    
yes, i already debug it, there's no error and every data is processed but not showed in listview
David Crow 22-Nov-20 22:32pm    
"...but not showed in listview"

You've shown bits and pieces of random sections of code, but what's actually important is nowhere to be found.

Have you considered discussing this in the actual Android forum? Show the relevant code there, rather than here in the Quick Answers section.

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