你的位置:首页 > 操作系统

[操作系统]谷歌电子市场7


1.对象封装

public class CategoryInfo {  public String name1;  public String name2;  public String name3;  public String url1;  public String url2;  public String url3;  public String title;  public boolean isTitle;// 表示当前对象是否是标题}

2.CategoryFragment

public class CategoryFragment extends BaseFragment {  private ArrayList<CategoryInfo> mList;  @Override  public View onCreateSuccessView() {    MyListView view = new MyListView(UIUtils.getContext());    view.setAdapter(new CategoryAdapter(mList));    return view;  }  @Override  public ResultState onLoad() {    CategoryProtocol protocol = new CategoryProtocol();    mList = protocol.getData(0);    return check(mList);  }  class CategoryAdapter extends MyBaseAdapter<CategoryInfo> {    public CategoryAdapter(ArrayList<CategoryInfo> list) {      super(list);    }    // 根据当前位置,返回相应的Holder对象    @Override    public BaseHolder<CategoryInfo> getHolder(int position) {      CategoryInfo info = getItem(position);      if (info.isTitle) {        return new TitleHolder();// 标题栏holder      }      return new CategoryHolder();// 普通类型holer    }    @Override    public ArrayList<CategoryInfo> onLoadMore() {      return null;    }    @Override    public boolean hasMore() {      return false;// 没有更多数据, 无需加载下一页    }    @Override    public int getViewTypeCount() {      return super.getViewTypeCount() + 1;// 在原来基础上,新增标题栏类型    }    // 根据位置判断当前item的类型    @Override    public int getInnerType(int position) {      CategoryInfo info = getItem(position);      if (info.isTitle) {// 标题栏类型        return super.getInnerType(position) + 1;      } else {// 普通类型        return super.getInnerType(position);      }    }  }}

3.Holder  

/** * 分类页标题栏holder */public class TitleHolder extends BaseHolder<CategoryInfo> {  private TextView tvTitle;  @Override  public View initView() {    View view = View.inflate(UIUtils.getContext(),        R.layout.list_item_title, null);    tvTitle = (TextView) view.findViewById(R.id.tv_title);    return view;  }  @Override  public void refreshView(CategoryInfo data) {    tvTitle.setText(data.title);  }}---------------------------------------------list_item_title.