Postingan lainnya
Remove secara otomatis
Saya punya masalah mengenai listview, saya ingin menghapus data yang tidak sama dengan data yang lain. pas saya mau running malah data yang kaga valid malah ikutan kebaca..
ini codingannya...
absensi_team.java
package com.example.eis2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.eis2.Item.ListViewAdapterCutiKhusus;
import com.example.eis2.Item.ListViewAdapterTeam;
import com.example.eis2.Item.absensiteammodel;
import com.example.eis2.Item.cutikhususmodel;
import com.example.eis2.Item.namanikmodel;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import static com.example.eis2.Item.ListViewAdapterTeam.lokasi;
import static com.example.eis2.Item.ListViewAdapterTeam.nikbaru2;
import static com.example.eis2.Item.LoginItem.KEY_NIK;
import static com.example.eis2.izin.txt_jabatan;
import static com.example.eis2.izin.txt_nomor;
import static com.example.eis2.izinfull.txt_lokasi;
import static com.example.eis2.spv_absensi.txt_jabatan_struktur;
import static com.example.eis2.spv_absensi.txt_lokasi_struktur;
public class absensi_team extends AppCompatActivity {
public ListView list;
private List<absensiteammodel> team;
private List<namanikmodel> movieItemList;
public static TextView lokasi2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_absensi_team);
final String nik_baru = getIntent().getStringExtra(KEY_NIK);
list = findViewById(R.id.list_team);
team = new ArrayList<>();
lokasi2 = (TextView) findViewById(R.id.lokasiteam);
movieItemList = new ArrayList<>();
getbiodata();
loadPlayer();
}
private void getbiodata () {
String nik_baru = getIntent().getStringExtra(KEY_NIK);
StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://hrd.tvip.co.id/rest_server/api/login/index?nik_baru=" + nik_baru,
new com.android.volley.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);
namanikmodel movieItem = new namanikmodel(
movieObject.getString("nama_karyawan_struktur"),
movieObject.getString("level_jabatan_karyawan"),
movieObject.getString("lokasi_struktur"),
movieObject.getString("jabatan_struktur")
);
movieItemList.add(movieItem);
lokasi2.setText(movieItem.getLokasi_struktur());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
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://hrd.tvip.co.id/rest_server/master/team/index?jabatan_struktur=" + jabatan,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
final JSONObject obj = new JSONObject(response);
JSONArray movieArray = obj.getJSONArray("data");
for (int i = 0; i < movieArray.length(); i++) {
final JSONObject movieObject = movieArray.getJSONObject(i);
final absensiteammodel movieItem = new absensiteammodel(
movieObject.getString("nik_baru"),
movieObject.getString("nama_karyawan_struktur"),
movieObject.getString("jabatan_karyawan"),
movieObject.getString("lokasi_struktur"));
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent i = new Intent(absensi_team.this, detail_absensi.class);
i.putExtra(KEY_NIK, nikbaru2.getText().toString());
startActivity(i);
System.out.println("Test :" + nikbaru2);
}
});
team.add(movieItem);
}
ListViewAdapterTeam adapter = new ListViewAdapterTeam(team, getApplicationContext());
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Maaf, anda belum pernah mengajukan cuti khusus", Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest1);
}
}
dan ini list view adapternya
package com.example.eis2.Item;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.example.eis2.R;
import com.example.eis2.absensi_team;
import com.example.eis2.detail_absensi;
import java.util.List;
import static com.example.eis2.Item.LoginItem.KEY_NIK;
import static com.example.eis2.absensi_team.lokasi2;
import static com.example.eis2.kehadiran.list;
import static com.example.eis2.spv_absensi.txt_jabatan_struktur;
import static com.example.eis2.spv_absensi.txt_lokasi_struktur;
public class ListViewAdapterTeam extends ArrayAdapter<absensiteammodel> {
List<absensiteammodel> team;
private Context context;
public static TextView nikbaru2, lokasi;
public ListViewAdapterTeam(List<absensiteammodel> team, Context context) {
super(context, R.layout.list_view_absensi_team, 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_view_absensi_team, null, true);
nikbaru2 = listViewItem.findViewById(R.id.nik);
TextView nama = listViewItem.findViewById(R.id.nama);
TextView jabatan = listViewItem.findViewById(R.id.jabatan);
lokasi = listViewItem.findViewById(R.id.lokasi);
absensiteammodel movieItem = team.get(position);
nikbaru2.setText(movieItem.getNikbaru());
nama.setText(movieItem.getNama_karyawan_struktur());
jabatan.setText(movieItem.getJabatan_struktur());
lokasi.setText(movieItem.getLokasi_struktur());
if(!lokasi2.getText().toString().equals(lokasi.getText().toString())){
team.remove(movieItem);
notifyDataSetChanged();
}
return listViewItem;
}
}
kira kira masalahnya apa ya ??
terima kasih kalau ada yang menjawab
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban