IntroduceGridAdapter.java 1.5 KB
package com.hh.xuetubao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hh.xuetubao.R;

import java.util.List;

public class IntroduceGridAdapter extends BaseAdapter {
    private List<String> list;
    private Context context;

    public IntroduceGridAdapter(List<String> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=LayoutInflater.from(context).inflate(R.layout.grid_introduce,null);
        TextView textView = (TextView) view.findViewById(R.id.tv_content);
        textView.setText(list.get(position));
        if(position%3==0){
            textView.setBackground(context.getResources().getDrawable(R.drawable.label_circle_blue));
        }else if(position%3==1){
            textView.setBackground(context.getResources().getDrawable(R.drawable.label_circle_blue));
        }else if(position%3==2){
            textView.setBackground(context.getResources().getDrawable(R.drawable.label_circle_green));
        }
        return view;
    }
}