Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyAdapter extends RecyclerView.Adapter<MyAdapter.RecyclerVH> {
- public static List<ContentItem> mHistoriList = null;
- History history;
- String[] spacecrafts;
- Context context;
- public MyAdapter(List<ContentItem> historiList) {
- mHistoriList=historiList;
- }
- @Override
- public RecyclerVH onCreateViewHolder(ViewGroup parent, int viewType) {
- View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.row_history,parent,false);
- return new RecyclerVH(v);
- }
- @Override
- public void onBindViewHolder(RecyclerVH holder, int position) {
- String tgl = mHistoriList.get(position).getDate();
- String substr = tgl.substring(0,10);
- String todays;
- DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy");
- Date dates =new Date();
- try {
- dates= formatter.parse(substr);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- todays=formatter.format(dates);
- Log.d("Tanggal format", todays);
- if(mHistoriList.get(position).getProduct()==null){
- holder.nameTxt.setText("Data Sudah terhapus atau Tidak ada");
- holder.productTxt.setText("");
- Glide.with(holder.imageView.getContext()).load(R.drawable.ic_broken_image_black_24dp).into(holder.imageView);
- holder.total.setText("Not Data");
- holder.tanggal.setText("");
- holder.location.setText("");
- }else{
- Locale localeID = new Locale("in", "ID");
- NumberFormat formatRupiah=NumberFormat.getCurrencyInstance(localeID);
- String Curency =formatRupiah.format((double)mHistoriList.get(position).getTotalPrice());
- Log.d("tgl Substr", substr);
- holder.nameTxt.setText(mHistoriList.get(position).getOrderNumber());
- holder.productTxt.setText(mHistoriList.get(position).getProduct().getProductName());
- Glide.with(holder.imageView.getContext()).load(mHistoriList.get(position).getProduct().getPictureLink()).into(holder.imageView);
- holder.total.setText(Curency);
- holder.tanggal.setText(todays);
- holder.location.setText(mHistoriList.get(position).getVendingMachine().getLocation());
- }
- }
- @Override
- public int getItemCount() {
- return mHistoriList.size();
- }
- /*
- VIEWHOLDER CLASS
- */
- public class RecyclerVH extends RecyclerView.ViewHolder
- {
- TextView nameTxt;
- TextView productTxt;
- ImageView imageView;
- TextView total;
- TextView tanggal;
- TextView location;
- public RecyclerVH(View itemView) {
- super(itemView);
- nameTxt= (TextView) itemView.findViewById(R.id.nameHistory);
- productTxt = (TextView)itemView.findViewById(R.id.nameProduct);
- total= (TextView) itemView.findViewById(R.id.price);
- tanggal= (TextView)itemView.findViewById(R.id.tglTransaksi);
- location= (TextView) itemView.findViewById(R.id.location);
- imageView = (ImageView)itemView.findViewById(R.id.productImage);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement