-
android:layout_height=“fill_parent”>
-
<ListView android:layout_width=“fill_parent”
-
android:layout_height=“wrap_content” android:id="@+id/MyListView">
list_items.xml
[java] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
-
android:orientation=“vertical” android:layout_width=“fill_parent”
-
android:layout_height=“wrap_content” android:id="@+id/myListItem"
-
android:paddingBottom=“4dip” android:paddingLeft=“12dip”
-
android:paddingRight=“12dip”>
-
<TextView android:layout_height=“wrap_content”
-
android:layout_width=“fill_parent” android:id="@+id/itemTitle"
-
android:textSize=“20dip” />
list_items_tag.xml
[java] view plain copy
123/article/details/7351606# “copy”)
- <?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:background="#555555" android:paddingLeft=“10dip”>
-
<TextView android:id="@+id/itemTitle" android:layout_width=“wrap_content”
-
android:layout_height=“20dip” android:textColor="#ffffff"
-
android:gravity=“center_vertical” />
MyAdapter.java
[java] view plain copy
-
package com.iaiai;
-
import java.util.List;
-
import java.util.Map;
-
import android.content.Context;
-
import android.view.LayoutInflater;
-
import android.view.View;
-
import android.view.ViewGroup;
-
import android.widget.BaseAdapter;
-
import android.widget.TextView;
-
public class MyAdapter extends BaseAdapter {
-
private LayoutInflater mInflater;
-
private List<Map<String, String>> listData;
-
private List<Map<String, String>> splitData;
-
public MyAdapter(Context context,
-
List<Map<String, String>> listData,
-
List<Map<String, String>> splitData) {
-
this.mInflater = LayoutInflater.from(context);
-
this.listData = listData;
-
this.splitData = splitData;
-
}
-
@Override
-
public int getCount() {
-
return listData.size();
-
}
-
@Override
-
public Object getItem(int position) {
-
return listData.get(position);
-
}
-
@Override
-
public long getItemId(int position) {
-
return position;
-
}
-
@Override
-
public boolean isEnabled(int position) {
-
if (splitData.contains(listData.get(position))) {
-
return false;
-
}
-
return super.isEnabled(position);
-
}
-
@Override
-
public View getView(final int position, View convertView, ViewGroup parent) {
-
if (splitData.contains(listData.get(position))) {
-
convertView = mInflater.inflate(R.layout.list_items_tag, null);
-
} else {
-
convertView = mInflater.inflate(R.layout.list_items, null);
-
}
-
TextView textView = (TextView) convertView.findViewById(R.id.itemTitle);
-
textView.setText(listData.get(position).get(“itemTitle”));
-
return convertView;
-
}
-
}
MainActivity.java
[java] view plain copy
-
package com.iaiai;
-
import java.util.ArrayList;
-
import java.util.HashMap;
-
import java.util.List;
-
import java.util.Map;
-
import android.app.Activity;
-
import android.os.Bundle;
-
import android.widget.ListView;
-
public class MainActivity extends Activity {