- private class MyAdapter extends BaseAdapter {
- List<Dev_Now_Info> infos;
- public MyAdapter(List<Dev_Now_Info> infos) {
- this.infos = infos;
- }
- @Override
- public int getCount() {
- return infos.size();
- }
- @Override
- public View getView(int position, View convertView, ViewGroup arg2) {
- ViewHolder holder = null;
- if (convertView == null) {
- holder = new ViewHolder();
- convertView = View.inflate(DevActivity.this, R.layout.dev_item, null);
- holder.tv_machine_addr = (TextView) convertView.findViewById(R.id.tv_machine_addr);
- holder.tv_matchine_state = (TextView) convertView.findViewById(R.id.tv_matchine_state);
- holder.tv_mdb_count = (TextView) convertView.findViewById(R.id.tv_mdb_count);
- holder.tv_ticket_count = (TextView) convertView.findViewById(R.id.tv_ticket_count);
- holder.tv_help_state = (TextView) convertView.findViewById(R.id.tv_help_state);
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder) convertView.getTag();
- resetViewHolder(holder);
- }
- Dev_Now_Info info = infos.get(position);
- holder.tv_machine_addr.setText("" + info.getDevAdr());
- String devState = "";
- if ("0".equals(info.getDevState())) {
- devState = "正常";
- } else if ("1".equals(info.getDevState())) {
- devState = "故障";
- holder.tv_matchine_state.setTextColor(Color.RED);
- } else if ("2".equals(info.getDevState())) {
- devState = "维护";
- }
- holder.tv_matchine_state.setText(devState);
- int mdbCount = info.getCashIn_1() + info.getCashIn_5() + info.getCashIn_10() + info.getCashIn_20()
- + info.getCashIn_50() + info.getCashIn_100() + info.getCashIn_500();
- holder.tv_mdb_count.setText(mdbCount + "");
- holder.tv_ticket_count.setText(info.getTicketCount() + "");
- String help = "";
- if ("0".equals(info.getIsHelp())) {
- help = "正常";
- } else if ("1".equals(info.getIsHelp())) {
- help = "有人求援";
- holder.tv_help_state.setTextColor(Color.RED);
- }
- holder.tv_help_state.setText(help);
-
- return convertView;
- }
- @Override
- public Object getItem(int arg0) {
- return infos.get(arg0);
- }
- @Override
- public long getItemId(int arg0) {
- return arg0;
- }
- }
- static class ViewHolder {
- private TextView tv_machine_addr;
- private TextView tv_matchine_state;
- private TextView tv_mdb_count;
- private TextView tv_ticket_count;
- private TextView tv_help_state;
- }
复制代码 |