Blame view

src/com/ectrip/cyt/adapter/StatisticsAdapter.java 2.8 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  package com.ectrip.cyt.adapter;
  
  import java.util.LinkedHashMap;
  import java.util.List;
  import java.util.Map;
  
  import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import com.ectrip.trips.check.R;
  
  public class StatisticsAdapter extends BaseAdapter {
  	private List<LinkedHashMap<String, String>> responsesList;
  	private Context context;
  	private int secondItemSize;
  
  	public StatisticsAdapter(Context context,
  							 List<LinkedHashMap<String, String>> responsesList) {
  		this.responsesList = responsesList;
  		this.context = context;
  		if (responsesList != null) {
  			Map<String, String> map = responsesList.get(0);
  			if (map != null) {
  				secondItemSize = map.size();
  			}
  		}
  	}
  
  	@Override
  	public int getCount() {
  		if (responsesList != null) {
  			return responsesList.size();
  		}
  		return 0;
  	}
  
  	@Override
  	public Map<String, String> getItem(int position) {
  		if (responsesList != null) {
  			return responsesList.get(position);
  		}
  		return null;
  	}
  
  	@Override
  	public long getItemId(int position) {
  		return position;
  	}
  
  	@Override
  	public View getView(int position, View convertView, ViewGroup parent) {
  		ViewHold hold = null;
  		if (convertView == null) {
  			hold = new ViewHold();
  			convertView = View.inflate(context, R.layout.statistic_day_item,
  					null);
  			LinearLayout itemLayout = (LinearLayout) convertView
  					.findViewById(R.id.itemLayout);
  			if (secondItemSize != 0) {
  				for (int i = 0; i < secondItemSize; i++) {
  					View item = View.inflate(context,
  							R.layout.statistic_day_item_item, null);
  					hold.product[i] = (TextView) item
  							.findViewById(R.id.product);
  					hold.product[i].setVisibility(View.GONE);
  					itemLayout.addView(item);
  				}
  			}
  			convertView.setTag(hold);
  		} else {
  			hold = (ViewHold) convertView.getTag();
  		}
  		if (getItem(position) != null) {
  			for(int i=0;i<secondItemSize;i++){
  				hold.product[i].setVisibility(View.GONE);
  			}
  			Map<String, String> temp = getItem(position);
  			int index=0;
  			for (Map.Entry<String, String> entry : temp.entrySet()) {
  				if (entry != null) {
  					if (entry.getValue() != null) {
  						hold.product[index].setText(entry.getValue());
  						hold.product[index].setVisibility(View.VISIBLE);
  						index++;
  					}else{
  						hold.product[index].setVisibility(View.GONE);
  					}
  				}
  			}
  			if(index!=secondItemSize){
  				for(int i=index;i<secondItemSize;i++){
  					hold.product[index].setVisibility(View.GONE);
  				}
  			}
  		}
  
  		return convertView;
  	}
  
  	public class ViewHold {
  		// 每件产品
  		TextView[] product = new TextView[secondItemSize];
  	}
  
  	public void notifyDataSetChanged(List<LinkedHashMap<String, String>> statisticsList) {
  		responsesList = statisticsList;
  		super.notifyDataSetChanged();
  	}
  }