package com.asfman.section;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class SectionAdapter extends BaseAdapter {
private ArrayList<HashMap<String, String>> data;
private Activity activity;
public SectionAdapter(ArrayList<HashMap<String, String>> data,
Activity activity) {
Log.i("info", "size:" + data.size());
this.data = data;
this.activity = activity;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.i("info", "getview:" + position);
@SuppressWarnings("unchecked")
HashMap<String, String> hashMap = (HashMap<String, String>) getItem(position);
if(hashMap.get("type") == null) Log.i("info", "fuckyou");
Log.i("info", hashMap.get("type"));
ViewHolder viewHolder;
if (hashMap.get("type") == "1") {
if(convertView == null || (convertView.getTag(R.id.fk) != null && (Integer) convertView.getTag(R.id.fk) != 1)) {
Log.i("info", "new 1");
convertView = activity.getLayoutInflater().inflate(
R.layout.simple_list_item_1, null);
TextView text1 = (TextView) convertView
.findViewById(android.R.id.text1);
viewHolder = new ViewHolder();
viewHolder.text1 = text1;
convertView.setTag(viewHolder);
convertView.setTag(R.id.fk, 1);
} else {
Log.i("info", "old 1");
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.text1.setText(hashMap.get("text1"));
} else {
if(convertView == null || (convertView.getTag(R.id.fk) != null && (Integer) convertView.getTag(R.id.fk) != 2)) {
Log.i("info", "new 2");
convertView = activity.getLayoutInflater().inflate(
R.layout.two_line_list_item, null);
TextView text1 = (TextView) convertView
.findViewById(android.R.id.text1);
TextView text2 = (TextView) convertView
.findViewById(android.R.id.text2);
viewHolder = new ViewHolder();
viewHolder.text1 = text1;
viewHolder.text2 = text2;
convertView.setTag(viewHolder);
convertView.setTag(R.id.fk, 2);
} else {
Log.i("info", "old 2");
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.text1.setText(hashMap.get("text1"));
viewHolder.text2.setText(hashMap.get("text2"));
}
return convertView;
}
private class ViewHolder {
TextView text1;
TextView text2;
}
}
posted on 2011-09-19 17:27
汪杰 阅读(212)
评论(0) 编辑 收藏 引用 所属分类:
Java