package com.andbase.patrol.gtDemo.adapter.pagesAdapter; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.GridView; import android.widget.TextView; import com.andbase.R; import com.andbase.patrol.gtDemo.activity.pages.Page1Activity; import com.andbase.patrol.gtDemo.model.Page1FormDemo; import com.andbase.patrol.gtDemo.model.PointStateDemo; import java.util.ArrayList; import java.util.List; /** * Created by lmx on 2018/2/26. */ public class Page1ListViewAdapter extends BaseAdapter { private Page1Activity mContext; private List<Page1FormDemo> lists; private LayoutInflater layinf; //GridView加载不同布局 public List<PointStateDemo> listPoint = null; public Page1ListViewAdapter(Page1Activity context, List<Page1FormDemo> lists){ this.mContext = context; this.lists = lists; layinf = LayoutInflater.from(context); } @Override public int getCount() { return lists.size(); } @Override public int getItemViewType(int position) { //根据position返回指定的布局类型,比如0、1,根据这个返回值加载不同布局 return lists.get(position).getPropertyType(); } @Override public int getViewTypeCount() { //这里是adapter里有几种布局 return 2; } @Override public Object getItem(int position) { return lists.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent){ Page1FormDemo form = lists.get(position); //第二个布局:进行中 ViewDoingHolder doingHolder = null; //第三个布局:已完成 ViewDoneHolder doneHolder = null; if (form == null) { return null; } if (convertView == null) { switch (form.getPropertyType()){ case 0: convertView = layinf.inflate(R.layout.page1_item1_demo, parent, false); //使用减少findView的次数 doingHolder = new Page1ListViewAdapter.ViewDoingHolder(); doingHolder.taskName = (TextView) convertView.findViewById(R.id.taskNameDoing); doingHolder.taskTime = (TextView) convertView.findViewById(R.id.taskTimeDoing); doingHolder.taskState = (TextView) convertView.findViewById(R.id.taskStateDoing); doingHolder.GridList = (GridView) convertView.findViewById(R.id.GridListDoing); doingHolder.okBtn = (Button) convertView.findViewById(R.id.okBtn); doingHolder.noBtn = (Button) convertView.findViewById(R.id.noBtn); //设置标记 convertView.setTag(doingHolder); break; case 1: convertView = layinf.inflate(R.layout.page1_item2_demo, parent, false); //使用减少findView的次数 doneHolder = new Page1ListViewAdapter.ViewDoneHolder(); doneHolder.taskName = (TextView) convertView.findViewById(R.id.taskNameDone); doneHolder.taskTime = (TextView) convertView.findViewById(R.id.taskTimeDone); doneHolder.taskState = (TextView) convertView.findViewById(R.id.taskStateDone); doneHolder.GridList = (GridView) convertView.findViewById(R.id.GridListDone); doneHolder.okBtn = (Button) convertView.findViewById(R.id.okBtn); doneHolder.noBtn = (Button) convertView.findViewById(R.id.noBtn); //设置标记 convertView.setTag(doneHolder); break; } } else { switch (form.getPropertyType()){ case 0: doingHolder = (Page1ListViewAdapter.ViewDoingHolder) convertView.getTag(); break; case 1: doneHolder = (Page1ListViewAdapter.ViewDoneHolder) convertView.getTag(); break; } } /** * 根据不同布局加载不同数据 * */ switch (form.getPropertyType()){ case 0: doingHolder.taskName.setText(form.getTaskName()); doingHolder.taskTime.setText(form.getTaskTime()); doingHolder.taskState.setText(form.getTaskState()); //GridView listPoint = new ArrayList<PointStateDemo>(); try { PointStateDemo form1 = new PointStateDemo(); form1.setPatrolStatusType(0); form1.setPatrolStatus("0"); form1.setPointName("1"); listPoint.add(form1); PointStateDemo form2 = new PointStateDemo(); form2.setPatrolStatusType(0); form2.setPatrolStatus("0"); form2.setPointName("2"); listPoint.add(form2); PointStateDemo form3 = new PointStateDemo(); form3.setPatrolStatusType(0); form3.setPatrolStatus("0"); form3.setPointName("3"); listPoint.add(form3); PointStateDemo form4 = new PointStateDemo(); form4.setPatrolStatusType(0); form4.setPatrolStatus("0"); form4.setPointName("4"); listPoint.add(form4); PointStateDemo form5 = new PointStateDemo(); form5.setPatrolStatusType(0); form5.setPatrolStatus("0"); form5.setPointName("5"); listPoint.add(form5); PointStateDemo form6 = new PointStateDemo(); form6.setPatrolStatusType(1); form6.setPatrolStatus("1"); form6.setPointName("6"); listPoint.add(form6); PointStateDemo form7 = new PointStateDemo(); form7.setPatrolStatusType(1); form7.setPatrolStatus("1"); form7.setPointName("7"); listPoint.add(form7); PointStateDemo form8 = new PointStateDemo(); form8.setPatrolStatusType(1); form8.setPatrolStatus("1"); form8.setPointName("8"); listPoint.add(form8); PointStateDemo form9 = new PointStateDemo(); form9.setPatrolStatusType(1); form9.setPatrolStatus("1"); form9.setPointName("9"); listPoint.add(form9); PointStateDemo form10 = new PointStateDemo(); form10.setPatrolStatusType(1); form10.setPatrolStatus("1"); form10.setPointName("10"); listPoint.add(form10); PointStateDemo form11 = new PointStateDemo(); form11.setPatrolStatusType(1); form11.setPatrolStatus("1"); form11.setPointName("11"); listPoint.add(form11); PointStateDemo form12 = new PointStateDemo(); form12.setPatrolStatusType(1); form12.setPatrolStatus("1"); form12.setPointName("12"); listPoint.add(form12); PointStateDemo form13 = new PointStateDemo(); form13.setPatrolStatusType(1); form13.setPatrolStatus("1"); form13.setPointName("13"); listPoint.add(form13); PointStateDemo form14 = new PointStateDemo(); form14.setPatrolStatusType(1); form14.setPatrolStatus("1"); form14.setPointName("14"); listPoint.add(form14); PointStateDemo form15 = new PointStateDemo(); form15.setPatrolStatusType(1); form15.setPatrolStatus("1"); form15.setPointName("15"); listPoint.add(form15); }catch(Exception ex) { Log.e("JSON Error: ", ex.toString()); } Page1Adapter page1Adapter = new Page1Adapter(mContext,listPoint); doingHolder.GridList.setAdapter(page1Adapter); break; case 1: doneHolder.taskName.setText(form.getTaskName()); doneHolder.taskTime.setText(form.getTaskTime()); doneHolder.taskState.setText(form.getTaskState()); //GridView listPoint = new ArrayList<PointStateDemo>(); try { PointStateDemo form1 = new PointStateDemo(); form1.setPatrolStatusType(0); form1.setPatrolStatus("0"); form1.setPointName("1"); listPoint.add(form1); PointStateDemo form2 = new PointStateDemo(); form2.setPatrolStatusType(0); form2.setPatrolStatus("0"); form2.setPointName("2"); listPoint.add(form2); PointStateDemo form3 = new PointStateDemo(); form3.setPatrolStatusType(0); form3.setPatrolStatus("0"); form3.setPointName("3"); listPoint.add(form3); PointStateDemo form4 = new PointStateDemo(); form4.setPatrolStatusType(0); form4.setPatrolStatus("0"); form4.setPointName("4"); listPoint.add(form4); PointStateDemo form5 = new PointStateDemo(); form5.setPatrolStatusType(0); form5.setPatrolStatus("0"); form5.setPointName("5"); listPoint.add(form5); PointStateDemo form6 = new PointStateDemo(); form6.setPatrolStatusType(0); form6.setPatrolStatus("0"); form6.setPointName("6"); listPoint.add(form6); PointStateDemo form7 = new PointStateDemo(); form7.setPatrolStatusType(0); form7.setPatrolStatus("0"); form7.setPointName("7"); listPoint.add(form7); PointStateDemo form8 = new PointStateDemo(); form8.setPatrolStatusType(0); form8.setPatrolStatus("0"); form8.setPointName("8"); listPoint.add(form8); PointStateDemo form9 = new PointStateDemo(); form9.setPatrolStatusType(0); form9.setPatrolStatus("0"); form9.setPointName("9"); listPoint.add(form9); PointStateDemo form10 = new PointStateDemo(); form10.setPatrolStatusType(0); form10.setPatrolStatus("0"); form10.setPointName("10"); listPoint.add(form10); PointStateDemo form11 = new PointStateDemo(); form11.setPatrolStatusType(0); form11.setPatrolStatus("0"); form11.setPointName("11"); listPoint.add(form11); PointStateDemo form12 = new PointStateDemo(); form12.setPatrolStatusType(0); form12.setPatrolStatus("0"); form12.setPointName("12"); listPoint.add(form12); PointStateDemo form13 = new PointStateDemo(); form13.setPatrolStatusType(0); form13.setPatrolStatus("0"); form13.setPointName("13"); listPoint.add(form13); PointStateDemo form14 = new PointStateDemo(); form14.setPatrolStatusType(0); form14.setPatrolStatus("0"); form14.setPointName("14"); listPoint.add(form14); PointStateDemo form15 = new PointStateDemo(); form15.setPatrolStatusType(0); form15.setPatrolStatus("0"); form15.setPointName("15"); listPoint.add(form15); }catch(Exception ex) { Log.e("JSON Error: ", ex.toString()); } Page1Adapter2 page1Adapter2 = new Page1Adapter2(mContext,listPoint); doneHolder.GridList.setAdapter(page1Adapter2); break; } return convertView; } /** * ViewHolder类 */ static class ViewDoingHolder { TextView taskName; TextView taskTime; TextView taskState; GridView GridList; Button noBtn; Button okBtn; } static class ViewDoneHolder { TextView taskName; TextView taskTime; TextView taskState; GridView GridList; Button noBtn; Button okBtn; } }
在ListView的adapter中设置private List<对象> gridViewList;这个对象在你new ListView的adapter时也携带过去,然后再ListView的adapter中 new GridView 的adapter然后把gridViewList的集合传递进去应该就Ok了
多谢