info。xml
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="10dp"
android:listSelector="@android:color/transparent"
android:cacheColorHint="#00000000"
>
info-adapter。xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/item_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="14sp"
android:textColor="#000000"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/item_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="12sp"
android:layout_weight="1"
android:textColor="#00BFFF"
/>
<TextView
android:id="@+id/item_text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:textSize="12sp"
android:textColor="#00BFFF"
android:layout_weight="1"
/>
<TextView
android:id="@+id/item_text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textSize="12sp"
android:textColor="#00BFFF"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
InfoForumAdapter extends BaseAdapter
private List<Map<String, Object>> datas;
private Context context;
public InfoForumAdapter(
Context context,
List<Map<String, Object>> datas) {
this.context = context;
this.datas = datas;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.datas.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return this.datas.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position,
View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.infoforum_adapt,null);
holder.itemText1 = (TextView) convertView.findViewById(R.id.item_text1);
holder.itemText2 = (TextView) convertView.findViewById(R.id.item_text2);
holder.itemText3 = (TextView) convertView.findViewById(R.id.item_text3);
holder.itemText4 = (TextView) convertView.findViewById(R.id.item_text4);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView
.getTag();
}
Map<String, Object> item = this.datas.get(position);
holder.itemText1.setText(item.get("forumContent").toString());
holder.itemText2.setText(item.get("personName").toString());
holder.itemText3.setText(item.get("personIndex").toString());
holder.itemText4.setText(item.get("reply").toString());
return convertView;
}
static class ViewHolder {
TextView itemText1;
TextView itemText2;
TextView itemText3;
TextView itemText4;
}
对应的activity
ListView listView = (ListView) findViewById(R.id.list);
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
String[] items = new String[]{
"帮妈妈求医!!!感谢大家帮忙! 10-22 16:14","黄磊","人气:2","回复:2"
};
for (int i=0;i<15;i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("forumContent",items[0]);
item.put("personName", items[1]);
item.put("personIndex",items[2]);
item.put("reply",items[3]);
results.add(item);
}
InfoForumAdapter textAdapt = new InfoForumAdapter(this, results);
listView.setAdapter(textAdapt);