登录+注册+商品列表+商品详情+购物车+删除

本文介绍了一个Android应用的实现过程,包括登录、注册、商品列表展示、商品详情查看、购物车功能以及商品删除。涉及到的组件和文件有activity布局、权限设置、网络请求、自定义属性、各个页面的Activity、Adapter、Model和Presenter等。同时,还使用了Retrofit和一些Utils工具类来辅助开发。
摘要由CSDN通过智能技术生成

*

效果图片:

**

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

首先我们先导依赖



 compile 'io.reactivex.rxjava2:rxjava:+'
    compile 'io.reactivex.rxjava2:rxandroid:+'
    compile 'com.squareup.retrofit2:adapter-rxjava2:+'
    compile 'com.squareup.retrofit2:retrofit:+'
    compile 'com.squareup.retrofit2:converter-gson:+'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.facebook.fresco:fresco:0.12.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'



网络权限:



    <uses-permission android:name="android.permission.INTERNET" />


注意的事项:

这里写图片描述

主布局activity_week3:



<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.a1510bdianshang2_master.Week3"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        >

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/jd_buy_icon"/>

    </RelativeLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/login_name"
        android:hint="请输入手机号"
        />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/login_user"
        android:hint="请输入密码"
        />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp">

        <CheckBox
            android:id="@+id/cb_mima"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="记住密码"
            />

        <TextView
            android:id="@+id/login_zhuce"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="新用户注册"
            android:layout_alignBaseline="@+id/cb_mima"
            android:layout_alignBottom="@+id/cb_mima"
            android:layout_alignParentEnd="true" />


    </RelativeLayout>


    <Button
        android:id="@+id/login_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="#fa843f"
        android:layout_gravity="center_horizontal"
        android:text="登录" />


</LinearLayout>



activity_shop


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rlv_shop"
        ></android.support.v7.widget.RecyclerView>

</LinearLayout>




activity_shop_xq



<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="391dp"
        android:id="@+id/shopxq_rlv"
        ></android.support.v7.widget.RecyclerView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

    <Button
        android:id="@+id/btn_jiaru"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="加入购物车"
        />
    <Button
        android:id="@+id/btn_goumai"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="立即购买"
        />
    </LinearLayout>
</LinearLayout>


activity_caractivity


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="购物车" />

        <TextView
            android:id="@+id/tv_bianji"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="编辑" />

    </RelativeLayout>

    <ExpandableListView
        android:id="@+id/exlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    </ExpandableListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="horizontal"
        android:padding="10dp">

        <CheckBox
            android:id="@+id/check_all"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:text="全选"
            android:textSize="15dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="总价:"
            android:textSize="15dp" />

        <TextView
            android:id="@+id/tv_zjprice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="0"
            android:textSize="15dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="数量:"
            android:textSize="15dp" />

        <TextView
            android:id="@+id/tv_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="0"
            android:textSize="15dp" />

        <Button
            android:id="@+id/btn_js"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_gravity="right"
            android:background="#fc0109"
            android:text="结算"
            android:textSize="15dp" />
    </LinearLayout>

</LinearLayout>



adddelete.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_delete"
        android:layout_width="31dp"
        android:layout_height="31dp"
        android:background="#999999"
        android:gravity="center"
        android:text="-" />

    <EditText
        android:id="@+id/ed_num"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@null"
        android:gravity="center" />

    <TextView
        android:id="@+id/tv_add"
        android:layout_width="31dp"
        android:layout_height="31dp"
        android:background="#999999"
        android:gravity="center"
        android:text="+" />

</LinearLayout>

gwc_goods_item.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:padding="10dp">

    <CheckBox
        android:id="@+id/check_gwc_goods"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:gravity="center_vertical" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_gwc_goods"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="title" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_gwc_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="价格:"
                android:textColor="#fa0000" />
        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.example.a1510bdianshang2_master.car.view.AddDeleteView
                android:id="@+id/add_delete"
                android:layout_width="100dp"
                android:layout_height="30dp"
                android:layout_centerVertical="true"
                android:layout_marginRight="5dp"
                app:left_item="-"
                app:middle_item="1"
                app:right_item="+" />

            <Button
                android:id="@+id/btn_gwc_delete"
                android:layout_width="110dp"
                android:layout_height="40dp"
                android:layout_alignParentRight="true"
                android:background="#f70496"
                android:gravity="center"
                android:text="删除"
                android:textColor="#ffffff" />

        </RelativeLayout>
    </LinearLayout>

    <ImageView
        android:id="@+id/img_gwc_goods"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@mipmap/ic_launcher" />
</LinearLayout>


gwc_group_item.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#999999"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <CheckBox
        android:id="@+id/check_gwc_group"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_marginLeft="20dp" />

    <TextView
        android:id="@+id/tv_gwc_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="title"
        android:textSize="20dp" />


</LinearLayout>


item_shop.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:id="@+id/shop_img"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/shop_price"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/shop_title"
            />

    </LinearLayout>

</LinearLayout>


shopxq_item.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">



    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:id="@+id/shpxq_img"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/shopxq_title"
        android:textSize="20dp"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/shopxq_price"
        android:textSize="30dp"
        android:textColor="#ff0000"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/shopxq_name"
        android:textSize="20dp"
        />

</LinearLayout>



在avlues里创建一个attrs,xml



<resources>
    <declare-styleable name="AddDeleteView">
        <attr name="left_item" format="string"></attr>
        <attr name="right_item" format="string"></attr>
        <attr name="middle_item" 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值