I have a problem when i create a list view using 2 url, here is my code
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
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
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
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
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