tlmarker1968

My recycle view problem

Oct 31st, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. This is the return from the API using Postman:
  2.  
  3. [
  4. {
  5. "id": 0,
  6. "ponumber": "5222019000730"
  7. },
  8. {
  9. "id": 1,
  10. "ponumber": "5222019000731"
  11. }
  12. ]
  13.  
  14. This is the code I am using in the app top retrieve the information:
  15.  
  16. private void readOutStandingPO() {
  17. PoList.clear();
  18. managerReceivingApi.getOutStandingPO(new Callback<ArrayList<ObjectPo>>() {
  19. @Override
  20. public void onResponse(@NonNull Call<ArrayList<ObjectPo>> call, @NonNull Response<ArrayList<ObjectPo>> response) {
  21. ArrayList<ObjectPo> JsonList = response.body();
  22. for (AtomicInteger i = new AtomicInteger(); i.get() < Objects.requireNonNull(JsonList).size(); i.getAndIncrement())
  23. PoList.add(new ObjectPo(
  24. JsonList.get(i.get()).getId(),
  25. JsonList.get(i.get()).getPoNum()
  26. ));
  27. pAdapter.notifyDataSetChanged();
  28. Toast.makeText(getApplicationContext(),"Out Standing PO's Loaded", Toast.LENGTH_SHORT).show();
  29. }
  30. @Override
  31. public void onFailure(@NonNull Call<ArrayList<ObjectPo>> call, @NonNull Throwable t) {
  32. Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
  33. }
  34. });
  35. }
  36.  
  37. This is the adapter for the recycleview I am using to display the list:
  38.  
  39. public class PoAdapter extends RecyclerView.Adapter<PoAdapter.PoViewHolder> {
  40. final private ArrayList<ObjectPo> mPoList;
  41. class PoViewHolder extends RecyclerView.ViewHolder {
  42. final Button mPoButton;
  43. PoViewHolder(View PoView) {
  44. super(PoView);
  45. mPoButton = PoView.findViewById(R.id.btnPO);
  46. }
  47. }
  48. PoAdapter(ArrayList<ObjectPo> PoList) {
  49. mPoList = PoList;
  50. }
  51. @NonNull
  52. @Override
  53. public PoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  54. View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_po, parent, false);
  55. return new PoViewHolder(v);
  56. }
  57. @Override
  58. public void onBindViewHolder(@NonNull PoViewHolder holder, int position) {
  59. final ObjectPo currentPo = mPoList.get(position);
  60. holder.mPoButton.setText(currentPo.getPoNum());
  61. holder.mPoButton.setOnClickListener(new View.OnClickListener() {
  62. @Override
  63. public void onClick(View view) {
  64.  
  65. }
  66. });
  67. }
  68.  
  69. @Override
  70. public int getItemCount() {
  71. return mPoList.size();
  72. }
  73. }
  74.  
  75. If you need more information please let me know.
Advertisement
Add Comment
Please, Sign In to add comment