package com.example.cosmosclient.views; import android.content.Context; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import com.example.cosmosclient.R; import org.askerov.dynamicgrid.BaseDynamicGridAdapter; import java.util.ArrayList; import java.util.List; public class CheeseDynamicAdapter extends BaseDynamicGridAdapter { public CheeseDynamicAdapter(Context context, List<?> items, int columnCount) { super(context, items, columnCount); } @Override public View getView(int position, View convertView, ViewGroup parent) { CheeseViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_grid, null); holder = new CheeseViewHolder(convertView); convertView.setTag(holder); } else { holder = (CheeseViewHolder) convertView.getTag(); } switch (position) { case 0: convertView.setBackgroundColor(Color.argb(100, 200, 100, 100)); break; case 1: convertView.setBackgroundColor(Color.argb(100, 200, 200, 100)); break; case 2: convertView.setBackgroundColor(Color.argb(100, 100, 100, 100)); break; case 3: convertView.setBackgroundColor(Color.argb(100, 200, 100, 200)); break; case 4: convertView.setBackgroundColor(Color.argb(100, 100, 200, 100)); break; case 5: convertView.setBackgroundColor(Color.argb(100, 100, 200, 200)); break; case 6: convertView.setBackgroundColor(Color.argb(100, 100, 100, 200)); break; } holder.build(getItem(position).toString()); return convertView; } private class CheeseViewHolder { private TextView titleText; private ListView itemList; //private ImageView image; private CheeseViewHolder(View view) { titleText = (TextView) view.findViewById(R.id.item_title); itemList = (ListView) view.findViewById(R.id.listview); //image = (ImageView) view.findViewById(R.id.item_img); /* ArrayList<String> items = new ArrayList<>(); items.add("からし"); items.add("わさび"); items.add("砂糖"); */ //ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), R.layout.item_list, items); //itemList.setAdapter(adapter); } void build(String title) { titleText.setText(title); //itemText.setText(items); //image.setImageResource(R.drawable.ic_launcher); } } }