Android实现listview tag,重写adapter
public class SoftListAdapter extends BaseAdapter {private Context context;private ArrayList<Map<String, Object>> list;public SoftListAdapter(Context con, ArrayList<Map<String, Object>> lis) {this.context = con;this.list = lis;}// 决定 getView循环几次@Overridepublic int getCount() {return list.size();}@Overridepublic Object getItem(int arg0) {return arg0;}@Overridepublic long getItemId(int position) {return position;}// 自定义适配方法@Overridepublic View getView(int position, View convertView, ViewGroup parent) {if (list.get(position).get("tag") != null&& (Boolean) list.get(position).get("tag")) {// 如果是标签项convertView = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.permission_soft_vlist_tag, null);} else {// 否则就是数据项convertView = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.permission_soft_vlist, null);ImageView img = (ImageView) convertView.findViewById(R.id.img);img.setImageDrawable((Drawable) list.get(position).get("img"));}TextView text = (TextView) convertView.findViewById(R.id.text);text.setText(list.get(position).get("text").toString());return convertView;}}
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>();map.put("text", tagString);map.put("tag", true);data.add(map);
<?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="fill_parent" android:orientation="horizontal" android:padding="5dip" > <ImageView android:id="@+id/img" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="center" android:layout_marginLeft="5dp" android:src="@drawable/ic_launcher" android:textColor="#FFFFFFFF" android:textSize="22dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="10dp" android:textColor="#FFFFFFFF" android:textSize="18dp" /></LinearLayout>
<?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="@drawable/background_color" android:paddingBottom="5dip" android:paddingLeft="10dip" android:paddingTop="5dip" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="20dip" android:gravity="center_vertical" android:textColor="#ffffff" > </TextView></LinearLayout>