GridViewAdapter.java 1.8 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.RelativeLayout;
import android.widget.TextView;

import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.AddressBean;

import java.util.List;

public class GridViewAdapter extends BaseAdapter {

    private List<AddressBean.PropListBean> list;
    private Context context;
    private int clickPosition;

    public GridViewAdapter(List<AddressBean.PropListBean> 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_content, null);
        TextView textView = (TextView) view.findViewById(R.id.text);
        textView.setText(list.get(position).getPropName());
        RelativeLayout relativeLayout = (RelativeLayout) view;
        if (position == clickPosition) {
            relativeLayout.setBackground(context.getResources().getDrawable(R.drawable.coners_5_orange));
            textView.setTextColor(context.getResources().getColor(R.color.color_ffffff));
        } else {
            relativeLayout.setBackground(context.getResources().getDrawable(R.drawable.coners_5_stoke));
            textView.setTextColor(context.getResources().getColor(R.color.color_6c6c6c));
        }
        return view;
    }

    public void setClickPosition(int clickPosition) {
        this.clickPosition = clickPosition;
    }


}