安卓购物车二级列表简单展示(仿京东,淘宝效果)

本文介绍了如何使用MVP框架(Retrofit+OkHttp+RxJava)在安卓应用中实现购物车的二级列表展示,类似于京东和淘宝的效果。首先,引入相关依赖并搭建MVP框架。接着,创建Model层的Api接口类,封装网络请求。在View层定义接口,包括成功和失败的回调方法。Presenter层包括两个类,用于处理业务逻辑。Adapter层涉及一级和二级列表的适配器实现。最后,在MainActivity中实现接口,并处理内存泄漏。记得添加网络权限,二级列表通过在一级列表的item中嵌套RecyclerView来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先导入依赖

implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.1.2'
implementation 'com.facebook.fresco:fresco:0.12.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.0.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.7.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.code.gson:gson:2.8.5'

//导入eventBus的依赖
implementation 'org.greenrobot:eventbus:3.1.1'
//butterknife依赖
implementation 'com.jakewharton:butterknife:9.0.0-rc1'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
//拦截器
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
//及解决冲突
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }
    }

}

(用的是Retrofit+OkHttp+RxJava)MVP框架

首先搭建好MVP框架(这个不用说)
然后解析一个二级列表购物车Bean类
在这里插入图片描述
model层创建一个Api接口类用来跟网络封装类拼接口

public class RetrofitOkRxUtils {

public OkHttpClient okHttpClient;
public final Api api;

private RetrofitOkRxUtils(){
    okHttpClient = new OkHttpClient.Builder()
            .connectTimeout(5, TimeUnit.SECONDS)
            .readTimeout(5,TimeUnit.SECONDS)
            .writeTimeout(5,TimeUnit.SECONDS)
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))//拦截器
            .build();
            //Retrofit+RxJava
    Retrofit retrofit = new Retrofit.Builder()
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl("http://172.17.8.100/")
            .build();
    api = retrofit.create(Api.class);
}
public static RetrofitOkRxUtils getInstance(){
    return OkHolder.instance;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值