AdapterMask.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.example.zhulinaapi;
  2. import android.content.Context;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.util.Base64;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.BaseAdapter;
  9. import android.widget.ImageView;
  10. import android.widget.TextView;
  11. import java.util.List;
  12. public class AdapterMask extends BaseAdapter {
  13. private Context mContext;
  14. List<Mask> maskList;
  15. public AdapterMask(Context mContext, List<Mask> maskList) {
  16. this.mContext = mContext;
  17. this.maskList = maskList;
  18. }
  19. @Override
  20. public int getCount() {
  21. return maskList.size();
  22. }
  23. @Override
  24. public Object getItem(int i) {
  25. return maskList.get(i);
  26. }
  27. @Override
  28. public long getItemId(int i) {
  29. return maskList.get(i).getId();
  30. }
  31. private Bitmap getUserImage(String encodedImg) {
  32. byte[] bytes = Base64.decode(encodedImg, Base64.DEFAULT);
  33. return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
  34. }
  35. @Override
  36. public View getView(int position, View convertView, ViewGroup parent) {
  37. View v = View.inflate(mContext, R.layout.item_mask, null);
  38. TextView day = v.findViewById(R.id.day);
  39. TextView wotkout = v.findViewById(R.id.wotkout);
  40. TextView trainer = v.findViewById(R.id.trainer);
  41. ImageView Image = v.findViewById(R.id.imageView);
  42. Mask mask = maskList.get(position);
  43. day.setText(mask.getday());
  44. wotkout.setText(mask.getwotkout());
  45. trainer.setText(mask.gettrainer());
  46. if (!mask.getImage().equals("null")) {
  47. Image.setImageBitmap(getUserImage(mask.getImage()));
  48. }
  49. return v;
  50. }
  51. }