多级分类菜单的实现

项目需要在商品分类页面生成多层菜单在网上搜了很多例子然后自己总结了一下写下来备用
项目技术:Gson解析
ListView与gridview相互嵌套
多层解析json
Picasso图片加载框架
此项目为三层分类,首先通过Gson解析获得第一层分类数据,接口比较简单Gson解析中使用了泛型,上代码:
接口形式
多级分类菜单的实现_第1张图片
多级分类菜单的实现_第2张图片
Gson解析过程
多级分类菜单的实现_第3张图片
多级分类菜单的实现_第4张图片
菜单界面
多级分类菜单的实现_第5张图片
实体类
这里写图片描述
gson解析第一层数据之后实现第一层菜单的OnItemClickListener得到第二层数据
多级分类菜单的实现_第6张图片
第二层菜单使用的是listview嵌套gridview实现的
为了避免滑动冲突的问题这里重写gridview
多级分类菜单的实现_第7张图片
二层菜单的item布局

 <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp" >

        <RelativeLayout
            android:id="@+id/rl1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/sort_tv_name_listandgridview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:text="特色分类"
                android:textColor="#444444"
                android:textSize="16sp" />
        RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rl1"
            android:paddingRight="25dp"
             >

            <zhaozhipeng.webview.utils.MyGridVeiw
                android:id="@+id/sort_list_gv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:horizontalSpacing="2dp"
                android:listSelector="@null"
                android:numColumns="3"
                android:stretchMode="columnWidth"
                android:verticalSpacing="2dp" >
            zhaozhipeng.webview.utils.MyGridVeiw>
        RelativeLayout>
    RelativeLayout>

在适配器中得到第三层数据
多级分类菜单的实现_第8张图片

附上关键代码下载地址:http://download.csdn.net/detail/qq_35061865/9712543

你可能感兴趣的:(多级分类菜单的实现)