这次说一下listview 的多条目展示
多条目展示 比普通的适配器要多两个方法 :
getItemViewType 设置多条目的类型,加一层判断
getViewTypeCount 有几种类型,写的要比它大,比如有两种类型,那就可以输入所有>2的
下面就是具体代码
class myAdapter extends BaseAdapter{
List<DateBean.ItemListBeanX.DataBeanX.ItemListBean> list;
public myAdapter(List<DateBean.ItemListBeanX.DataBeanX.ItemListBean> list) {
this.list = list;
}
@Override
public int getItemViewType(int position) {
if (position%2==0){
return TYPE_0;
}else {
return TYPE_1;
}
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
//获取类型
int type = getItemViewType(i);
//两种类型,两个viewHolder
viewHolder1 holder1 = null;
//具体实现内容看清楚
switch (type){
case 0:
if (view==null){
view = View.inflate(getActivity(),R.layout.er,null);
holder0=new viewHolder0();
holder0.text_1 = (TextView) view.findViewById(R.id.text1_f1);
holder0.img_1= (ImageView) view.findViewById(R.id.img1_f1);
view.setTag(holder0);
}else {
holder0 = (viewHolder0) view.getTag();
}
break;
case 1:
if (view==null){
view = View.inflate(getActivity(),R.layout.san,null);
holder1 = new viewHolder1();
holder1.text_2 = (TextView) view.findViewById(R.id.text2_f1);
holder1.img_2= (ImageView) view.findViewById(R.id.img2_f1);
view.setTag(holder1);
}else {
holder1 = (viewHolder1) view.getTag();
}
break;
}
//虽然控件是一样多的,但是位置是不一样的,XMl文件就不写了
case 0:
holder0.text_1.setText(list.get(i).getData().getTitle());
loderImage(list.get(i).getData().getImage(),holder0.img_1);
break;
case 1:
holder1.text_2.setText(list.get(i).getData().getTitle());
loderImage(list.get(i).getData().getImage(),holder1.img_2);
break;
}
return view;
}
class viewHolder0{
ImageView img_1;
TextView text_1;
}
class viewHolder1{
ImageView img_2;
TextView text_2;
}
}
以上就是我分享的listview 的多条目展示,还有一些不足和没有说到的,请多多包涵
PS:有不同的方法,这是我掌握的