Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is the return from the API using Postman:
- [
- {
- "id": 0,
- "ponumber": "5222019000730"
- },
- {
- "id": 1,
- "ponumber": "5222019000731"
- }
- ]
- This is the code I am using in the app top retrieve the information:
- private void readOutStandingPO() {
- PoList.clear();
- managerReceivingApi.getOutStandingPO(new Callback<ArrayList<ObjectPo>>() {
- @Override
- public void onResponse(@NonNull Call<ArrayList<ObjectPo>> call, @NonNull Response<ArrayList<ObjectPo>> response) {
- ArrayList<ObjectPo> JsonList = response.body();
- for (AtomicInteger i = new AtomicInteger(); i.get() < Objects.requireNonNull(JsonList).size(); i.getAndIncrement())
- PoList.add(new ObjectPo(
- JsonList.get(i.get()).getId(),
- JsonList.get(i.get()).getPoNum()
- ));
- pAdapter.notifyDataSetChanged();
- Toast.makeText(getApplicationContext(),"Out Standing PO's Loaded", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onFailure(@NonNull Call<ArrayList<ObjectPo>> call, @NonNull Throwable t) {
- Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- }
- This is the adapter for the recycleview I am using to display the list:
- public class PoAdapter extends RecyclerView.Adapter<PoAdapter.PoViewHolder> {
- final private ArrayList<ObjectPo> mPoList;
- class PoViewHolder extends RecyclerView.ViewHolder {
- final Button mPoButton;
- PoViewHolder(View PoView) {
- super(PoView);
- mPoButton = PoView.findViewById(R.id.btnPO);
- }
- }
- PoAdapter(ArrayList<ObjectPo> PoList) {
- mPoList = PoList;
- }
- @NonNull
- @Override
- public PoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_po, parent, false);
- return new PoViewHolder(v);
- }
- @Override
- public void onBindViewHolder(@NonNull PoViewHolder holder, int position) {
- final ObjectPo currentPo = mPoList.get(position);
- holder.mPoButton.setText(currentPo.getPoNum());
- holder.mPoButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- }
- });
- }
- @Override
- public int getItemCount() {
- return mPoList.size();
- }
- }
- If you need more information please let me know.
Advertisement
Add Comment
Please, Sign In to add comment