Google electronics market 7-category, Google electronics market 7 --
1. Object Encapsulation
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; // indicates whether the current object is the title}
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 );} // return the corresponding Holder object @ Override public BaseHolder <CategoryInfo> getHolder (int position) {CategoryInfo info = getItem (position); if (info. isTitle) {return new TitleHolder (); // Title Bar holder} return new CategoryHolder (); // normal holer} @ Override public ArrayList <CategoryInfo> onLoadMore () {return null ;}@ Override public boolean hasMore () {return false; // no more data, no need to load the next page} @ Override public int getViewTypeCount () {return super. getViewTypeCount () + 1; // based on the original title bar type} // determine the type of the current item based on the position @ Override public int getInnerType (int position) {CategoryInfo info = getItem (position); if (info. isTitle) {// return super. getInnerType (position) + 1;} else {// normal type return super. getInnerType (position );}}}}
3. Holder
/*** Category page title bar holder */public class TitleHolder extends BaseHolder <CategoryInfo> {private TextView tvTitle; @ Override public View initView () {View 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 );}}----------------------- Export 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> ---- Classification/*** classification 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 = View. inflat E (UIUtils. getContext (), R. layout. list_item_category, null); mBitmapUtils = BitmapHelper. getBitmapUtils (); mBitmapUtils. configdefaloadloadingimage (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;} @ Ove Rride 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 = "casual" 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 = "casual" 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 = "casual" android: textColor = "#000" android: textSize = "16sp"/> </LinearLayout>