AnswerSheetGridAdapter.java 1.6 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 AnswerSheetGridAdapter extends BaseAdapter {

    private List<Integer> list;
    private Context context;
    private int thisPosition;
    private int thisState;

    public AnswerSheetGridAdapter(List<Integer> 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.pop_answer_grid, null);
        TextView content = (TextView) view.findViewById(R.id.content);
        content.setText(String.valueOf(position + 1));

        if (list.get(position) == 0) {
            content.setBackground(content.getResources().getDrawable(R.drawable.circle_gray));
        } else if (list.get(position) == 1) {
            content.setBackground(content.getResources().getDrawable(R.drawable.circle_green));
        } else if (list.get(position) == 2) {
            content.setBackground(content.getResources().getDrawable(R.drawable.circle_red));
        }

        return view;
    }

}