Android一个ListView列表之中插入两种不同的数据
http://www.cnblogs.com/roucheng/ Android一个ListView列表之中插入两种不同的数据
代码如下:
public class ViewHolder{ Button fenzu_btn_1; Button fenzu_btn_2; Button fenzu_btn_3; } public class ViewHolder1{ TextView tvTitle; TextView tvLetter; } /** * 当ListView数据发生变化时,调用此方法来更新ListView * @param list http://www.cnblogs.com/roucheng/p/csslogin.html */ public void updateListView(List<SortModel> list){ this.list = list; notifyDataSetChanged(); } public int getCount() { return this.list.size(); } public Object getItem(int position) { return list.get(position); } @Override public int getItemViewType(int position) { // TODO Auto-generated method stub int p = position; if (p == 0) return 0; else return 1; } @Override public int getViewTypeCount() { return 2; } public View getView(final int position, View view, ViewGroup arg2) { int type = getItemViewType(position); if (view == null) { inflater = LayoutInflater.from(mContext); if(type==1){ view = inflater.inflate(R.layout.item,arg2, false); viewHolder1 = new ViewHolder1(); viewHolder1.tvTitle= (TextView) view.findViewById(R.id.title); viewHolder1.tvLetter= (TextView) view.findViewById(R.id.catalog); view.setTag(viewHolder1); }else{ //http://www.cnblogs.com/roucheng/p/csslogin.html view = inflater.inflate(R.layout.items2,arg2, false); fenzu_btn_1=(LinearLayout)view.findViewById(R.id.fenzu_btn_1); view.setTag(viewHolder); } } else { switch (type) { case 1: viewHolder1 = (ViewHolder1) view.getTag(); break; case 0: viewHolder = (ViewHolder) view.getTag(); break; } } return view; }