网络访问json数组传入listview

1.配置文件设置网络权限及http明文请求

<uses-permission android:name="android.permission.INTERNET"/>
//在application中再添加
android:usesCleartextTraffic="true"

2.添加依赖

选择Gradle Scripts下要运行该Activity的模块项目,添加依赖

因为我的项目名是wik2所以就选择build.gradle(Module:******.wik2)然后在依赖里添加以下代码

    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation  'com.google.code.gson:gson:2.8.6'

3.创建布局

主布局(一个listview和一个button。“主布局名listviewwangluotupian2")

    <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ListView
        android:id="@+id/listview"
        android:layout_width="409dp"
        android:layout_height="681dp"
        android:layout_marginStart="1dp"
        android:layout_marginTop="1dp"
        android:layout_marginEnd="1dp"
        android:layout_marginBottom="1dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button4" />
</androidx.constraintlayout.widget.ConstraintLayout>

子布局(Imageview,3个textview) 如图

 子布局代码("子布局名pictureliulan2")

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="90dp"
        android:layout_height
  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值