Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.kamil.miniprojekt1;
- import android.content.Context;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import java.util.List;
- import android.widget.TextView;
- import android.graphics.Color;
- import android.view.LayoutInflater;
- /**
- * Created by Kamil on 04.11.2017.
- */
- public class MyArrayAdapter extends ArrayAdapter
- {
- private TextView textView;
- private List<Product> products;
- private int rozmiar, kolor;
- public MyArrayAdapter(Context context, int text_view_res_id, List<Product> elements, int rozmiar, int kolor) {
- super(context, text_view_res_id, elements);
- this.products=elements;
- this.rozmiar = rozmiar;
- this.kolor = kolor;
- }
- @Override
- public int getCount() {
- return products.size();
- }
- @Override
- public Product getItem(int position) {
- return products.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(int position, View view, ViewGroup parent)
- {
- if (view == null) {
- LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
- }
- Product p = getItem(position);
- String s = p.getNazwa()+" ; "+p.getCena()+" ; "+p.getIlosc();
- textView = view.findViewById(android.R.id.text1);
- textView.setTextColor(kolor);
- textView.setTextSize(rozmiar);
- textView.setText(s);
- if(p.isCzyKupione())
- textView.setBackgroundColor(Color.GREEN);
- else
- textView.setBackgroundColor(Color.RED);
- return view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement