listview设置不同选项的点击效果

public class MySimpleAdapter extends BaseAdapter {
    private LayoutInflater mInflater;

    private List> dataList;

    public MySimpleAdapter(Context context, List> data) {
        mInflater = LayoutInflater.from(context);
        this.dataList = data;
    }

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

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.color_list_item, null);
            holder = new ViewHolder();
            holder.blue = (TextView)convertView.findViewById(R.id.blue_item);
            holder.red = (TextView)convertView.findViewById(R.id.red_item);
            holder.green = (TextView)convertView.findViewById(R.id.green_item);
            holder.yellow = (TextView)convertView.findViewById(R.id.yellow_item);

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder)convertView.getTag();

        }
        holder.blue.setText((CharSequence)dataList.get(position).get("blue"));
        holder.red.setText((CharSequence)dataList.get(position).get("red"));
        holder.green.setText((CharSequence)dataList.get(position).get("green"));
        holder.yellow.setText((CharSequence)dataList.get(position).get("yellow"));
        if ("blue".equals(dataList.get(position).get("status").toString())) {
            convertView.setBackgroundResource(R.drawable.item_chang_blue);
        } else if ("red".equals(dataList.get(position).get("status").toString())) {
            convertView.setBackgroundResource(R.drawable.item_chang_red);
        } else if ("green".equals(dataList.get(position).get("status").toString())) {
            convertView.setBackgroundResource(R.drawable.flightinfo_item_chang_green);
        } else if ("yellow".equals(dataList.get(position).get("status").toString())) {
            convertView.setBackgroundResource(R.drawable.flightinfo_item_chang_yellow);
        } 
        return convertView;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }

    class ViewHolder {
        TextView blue;
        TextView red;
        TextView green;
        TextView yellow;
    }
    
}

选择器item_chang_blue.xml 其他同理



   
         
            
         
    
    
     
         
            
         
     
  


你可能感兴趣的:(Android)