Advertisement
Dilan1991

Untitled

Mar 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1.  
  2. public class MyAdapter extends RecyclerView.Adapter<MyAdapter.RecyclerVH> {
  3. public static List<ContentItem> mHistoriList = null;
  4. History history;
  5. String[] spacecrafts;
  6. Context context;
  7. public MyAdapter(List<ContentItem> historiList) {
  8. mHistoriList=historiList;
  9.  
  10.  
  11. }
  12.  
  13.  
  14.  
  15. @Override
  16. public RecyclerVH onCreateViewHolder(ViewGroup parent, int viewType) {
  17. View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.row_history,parent,false);
  18. return new RecyclerVH(v);
  19. }
  20.  
  21. @Override
  22. public void onBindViewHolder(RecyclerVH holder, int position) {
  23. String tgl = mHistoriList.get(position).getDate();
  24. String substr = tgl.substring(0,10);
  25. String todays;
  26. DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy");
  27. Date dates =new Date();
  28. try {
  29. dates= formatter.parse(substr);
  30. } catch (ParseException e) {
  31. e.printStackTrace();
  32. }
  33. todays=formatter.format(dates);
  34.  
  35. Log.d("Tanggal format", todays);
  36.  
  37. if(mHistoriList.get(position).getProduct()==null){
  38. holder.nameTxt.setText("Data Sudah terhapus atau Tidak ada");
  39. holder.productTxt.setText("");
  40. Glide.with(holder.imageView.getContext()).load(R.drawable.ic_broken_image_black_24dp).into(holder.imageView);
  41. holder.total.setText("Not Data");
  42. holder.tanggal.setText("");
  43. holder.location.setText("");
  44.  
  45. }else{
  46.  
  47. Locale localeID = new Locale("in", "ID");
  48. NumberFormat formatRupiah=NumberFormat.getCurrencyInstance(localeID);
  49. String Curency =formatRupiah.format((double)mHistoriList.get(position).getTotalPrice());
  50.  
  51. Log.d("tgl Substr", substr);
  52. holder.nameTxt.setText(mHistoriList.get(position).getOrderNumber());
  53. holder.productTxt.setText(mHistoriList.get(position).getProduct().getProductName());
  54. Glide.with(holder.imageView.getContext()).load(mHistoriList.get(position).getProduct().getPictureLink()).into(holder.imageView);
  55. holder.total.setText(Curency);
  56. holder.tanggal.setText(todays);
  57. holder.location.setText(mHistoriList.get(position).getVendingMachine().getLocation());
  58.  
  59. }
  60.  
  61.  
  62.  
  63. }
  64.  
  65. @Override
  66. public int getItemCount() {
  67. return mHistoriList.size();
  68. }
  69.  
  70. /*
  71. VIEWHOLDER CLASS
  72. */
  73. public class RecyclerVH extends RecyclerView.ViewHolder
  74. {
  75. TextView nameTxt;
  76. TextView productTxt;
  77. ImageView imageView;
  78.  
  79. TextView total;
  80. TextView tanggal;
  81. TextView location;
  82.  
  83. public RecyclerVH(View itemView) {
  84. super(itemView);
  85. nameTxt= (TextView) itemView.findViewById(R.id.nameHistory);
  86. productTxt = (TextView)itemView.findViewById(R.id.nameProduct);
  87. total= (TextView) itemView.findViewById(R.id.price);
  88. tanggal= (TextView)itemView.findViewById(R.id.tglTransaksi);
  89. location= (TextView) itemView.findViewById(R.id.location);
  90. imageView = (ImageView)itemView.findViewById(R.id.productImage);
  91.  
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement