谷歌电子市场7--分类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谷歌电子市场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.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000" android:textSize="18sp" /> </LinearLayout> -------------------------------------------------- /** * 分类holder * * @author Kevin */ public class CategoryHolder extends BaseHolder<CategoryInfo> implements OnClickListener { private ImageView ivIcon1, ivIcon2, ivIcon3; private TextView tvName1, tvName2, tvName3; private LinearLayout llGrid1, llGrid2, llGrid3; private BitmapUtils mBitmapUtils; @Override public View initView() { View view = View.inflate(UIUtils.getContext(), R.layout.list_item_category, null); mBitmapUtils = BitmapHelper.getBitmapUtils(); mBitmapUtils.configDefaultLoadingImage(R.drawable.ic_default); ivIcon1 = (ImageView) view.findViewById(R.id.iv_icon1); ivIcon2 = (ImageView) view.findViewById(R.id.iv_icon2); ivIcon3 = (ImageView) view.findViewById(R.id.iv_icon3); tvName1 = (TextView) view.findViewById(R.id.tv_name1); tvName2 = (TextView) view.findViewById(R.id.tv_name2); tvName3 = (TextView) view.findViewById(R.id.tv_name3); llGrid1 = (LinearLayout) view.findViewById(R.id.ll_grid1); llGrid2 = (LinearLayout) view.findViewById(R.id.ll_grid2); llGrid3 = (LinearLayout) view.findViewById(R.id.ll_grid3); llGrid1.setOnClickListener(this); llGrid2.setOnClickListener(this); llGrid3.setOnClickListener(this); return view; } @Override public void refreshView(CategoryInfo data) { if (data != null) { tvName1.setText(data.name1); tvName2.setText(data.name2); tvName3.setText(data.name3); mBitmapUtils.display(ivIcon1, HttpHelper.URL + "image?name=" + data.url1); mBitmapUtils.display(ivIcon2, HttpHelper.URL + "image?name=" + data.url2); mBitmapUtils.display(ivIcon3, HttpHelper.URL + "image?name=" + data.url3); } } @Override public void onClick(View v) { CategoryInfo data = getData(); switch (v.getId()) { case R.id.ll_grid1: Toast.makeText(UIUtils.getContext(), data.name1, Toast.LENGTH_SHORT) .show(); break; case R.id.ll_grid2: Toast.makeText(UIUtils.getContext(), data.name2, Toast.LENGTH_SHORT) .show(); break; case R.id.ll_grid3: Toast.makeText(UIUtils.getContext(), data.name3, Toast.LENGTH_SHORT) .show(); break; default: break; } } } -------------------------------------------- list_item_category.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:orientation="horizontal" > <LinearLayout android:id="@+id/ll_grid1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/grid_item_bg_selector" android:gravity="center" android:orientation="vertical" android:padding="5dp" > <ImageView android:id="@+id/iv_icon1" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/ic_default" /> <TextView android:id="@+id/tv_name1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="休闲" android:textColor="#000" android:textSize="16sp" /> </LinearLayout> <LinearLayout android:id="@+id/ll_grid2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/grid_item_bg_selector" android:gravity="center" android:orientation="vertical" android:padding="5dp" > <ImageView android:id="@+id/iv_icon2" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/ic_default" /> <TextView android:id="@+id/tv_name2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="休闲" android:textColor="#000" android:textSize="16sp" /> </LinearLayout> <LinearLayout android:id="@+id/ll_grid3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/grid_item_bg_selector" android:gravity="center" android:orientation="vertical" android:padding="5dp" > <ImageView android:id="@+id/iv_icon3" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/ic_default" /> <TextView android:id="@+id/tv_name3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="休闲" android:textColor="#000" android:textSize="16sp" /> </LinearLayout> </LinearLayout>
以上是关于谷歌电子市场7--分类的主要内容,如果未能解决你的问题,请参考以下文章