Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package com.example.kamil.miniprojekt1;
  2.  
  3. import android.content.Context;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.ArrayAdapter;
  7. import java.util.List;
  8. import android.widget.TextView;
  9. import android.graphics.Color;
  10. import android.view.LayoutInflater;
  11.  
  12.  
  13. /**
  14.  * Created by Kamil on 04.11.2017.
  15.  */
  16.  
  17. public class MyArrayAdapter extends ArrayAdapter
  18. {
  19.     private TextView textView;
  20.     private List<Product> products;
  21.     private int rozmiar, kolor;
  22.  
  23.     public MyArrayAdapter(Context context, int text_view_res_id, List<Product> elements, int rozmiar, int kolor) {
  24.         super(context, text_view_res_id, elements);
  25.         this.products=elements;
  26.         this.rozmiar = rozmiar;
  27.         this.kolor = kolor;
  28.     }
  29.  
  30.     @Override
  31.     public int getCount() {
  32.         return products.size();
  33.     }
  34.  
  35.     @Override
  36.     public Product getItem(int position) {
  37.         return products.get(position);
  38.     }
  39.  
  40.     @Override
  41.     public long getItemId(int position) {
  42.         return position;
  43.     }
  44.  
  45.     @Override
  46.     public View getView(int position, View view, ViewGroup parent)
  47.     {
  48.         if (view == null) {
  49.             LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  50.             view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
  51.         }
  52.  
  53.         Product p = getItem(position);
  54.         String s = p.getNazwa()+" ; "+p.getCena()+" ; "+p.getIlosc();
  55.  
  56.         textView = view.findViewById(android.R.id.text1);
  57.  
  58.         textView.setTextColor(kolor);
  59.         textView.setTextSize(rozmiar);
  60.  
  61.         textView.setText(s);
  62.  
  63.         if(p.isCzyKupione())
  64.             textView.setBackgroundColor(Color.GREEN);
  65.         else
  66.             textView.setBackgroundColor(Color.RED);
  67.  
  68.         return view;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement