网络请求Adapter添加数据
一般在开发中我们都需要在listview中添加数据显示在界面上
1.首先我们会在布局中写一个listview
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#EFEFF4"
- android:clipChildren="false"
- >
- <ListView
- android:id="@+id/id_rada_list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="10dp"
- android:divider="#00000000"/>
- </FrameLayout>
2.初始化listview的布局控件
- ListView rada_list = findViewById(R.id.id_rada_list);
3.网络请求数据在listview中加载adapter
- rada_list.setAdapter(new MyListAdapter());
4.关键步骤adapter添加数据
- //listview 设置适配器
- class MyListAdapter extends BaseAdapter {
- private DisplayImageOptions options;
- public MyListAdapter() {
- options = new DisplayImageOptions.Builder()
- .showImageOnLoading(R.drawable.logo)//加载中图片的设置
- .showImageForEmptyUri(R.drawable.logo)//url为null的情况下
- .showImageOnFail(R.drawable.logo)//加载图片失败的时候的设置
- .cacheInMemory(true)//是否缓存在内存
- .cacheOnDisk(true)//是否缓存在硬盘
- .considerExifParams(true)//exif:一张图片的附加信息 位置信息、时间信息、角度
- .displayer(new FadeInBitmapDisplayer(500))//设置展示器
- .build();
- }
- @Override
- public int getCount() {
- return redEnvelope.size();
- }
- @Override
- public Object getItem(int position) {
- return redEnvelope.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- ViewHolder holder = null;
- if (convertView == null) {
- convertView = View.inflate(getApplication(), R.layout.item_radar, null);
- holder = new ViewHolder();
- holder.ivImageview = convertView.findViewById(R.id.iv_rade_image);
- holder.tvName = convertView.findViewById(R.id.tv_name);
- holder.tvMonkey = convertView.findViewById(R.id.tv_money);
- holder.tvNuber = convertView.findViewById(R.id.tv_nuber);
- holder.btCome = convertView.findViewById(R.id.bt_come);
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder) convertView.getTag();
- }
- holder.tvName.setText(redEnvelope.get(position).getNickname() + "");
- DecimalFormat format = new DecimalFormat("#.##");
- double aAmount = redEnvelope.get(position).getActualAmount();
- holder.tvMonkey.setText(format.format(aAmount));
- holder.tvNuber.setText(redEnvelope.get(position).getNumber() + "");
- String photoUrl = redEnvelope.get(position).getPhotoUrl();
- // String url = GlobalConstants.URL_PREFIX + news.get(position).listimage;
- ImageLoader.getInstance().displayImage(photoUrl, holder.ivImageview, options);
- holder.btCome.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {//点击红包雷达 去抢红包
- if(redNum == 0){
- DialogBuilder.messageDialog(RadarActivity.this).setMessage("您的抢红包次数已使用完啦!!!").show();
- return;
- }
- nickname = redEnvelope.get(position).getNickname();
- photoUrl1 = redEnvelope.get(position).getPhotoUrl();
- actualAmount = redEnvelope.get(position).getActualAmount();
- id = redEnvelope.get(position).getId();
- number = redEnvelope.get(position).getNumber();
- pos = position;
- toValidate();
- }
- });
- return convertView;
- }
- }
- //非静态内部类会默认拥有外部类的实例对象
- static class ViewHolder {
- public ImageView ivImageview;
- public TextView tvName;
- public TextView tvMonkey;
- public TextView tvNuber;
- public Button btCome;
- }
6.adtpter布局文件
- <?xml version="1.0" encoding="utf-8"?>
- <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"
- android:fitsSystemWindows="true"
- android:orientation="vertical">
- <LinearLayout
- android:id="@+id/ll_pay_wx"
- android:layout_width="match_parent"
- android:layout_height="80dp"
- android:layout_marginLeft="16dp"
- android:background="#FFFFFF"
- android:layout_marginRight="13dp"
- android:gravity="center_vertical">
- <com.netease.nim.avchatkit.common.imageview.CircleImageView
- android:id="@+id/iv_rade_image"
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:layout_marginEnd="8dp"
- android:layout_marginLeft="8dp"
- android:layout_marginRight="8dp"
- android:layout_marginStart="8dp"
- app:civ_border_color="#fffed470"
- app:civ_border_width="2dp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="@+id/constraintLayout"
- app:srcCompat="@drawable/logo" />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="17dp"
- android:orientation="vertical">
- <TextView
- android:id="@+id/tv_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="2dp"
- android:text="红聊科技
- " android:textColor="#000000"
- android:textSize="15sp"/>
- <RelativeLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:id="@+id/tv_read_yuer"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#666666"
- android:textSize="13sp"
- android:text="剩余"/>
- <TextView
- android:id="@+id/tv_money"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/tv_read_yuer"
- android:text="1000"
- android:textSize="13sp"
- android:textColor="#ff533c"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/tv_money"
- android:text="元"
- android:textSize="13sp"
- android:textColor="#666666"/>
- <TextView
- android:id="@+id/tv_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="90dp"
- android:textSize="13sp"
- android:textColor="#666666"
- android:text="剩余"/>
- <TextView
- android:id="@+id/tv_nuber"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/tv_view"
- android:text="10"
- android:textSize="13sp"
- android:textColor="#666666"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/tv_nuber"
- android:text="个红包"
- android:textSize="13sp"
- android:textColor="#666666"/>
- </RelativeLayout>
- <Button
- android:id="@+id/bt_come"
- android:layout_width="73dp"
- android:layout_height="27dp"
- android:layout_marginLeft="170dp"
- android:layout_marginTop="-22dp"
- android:textColor="#504f4f"
- style="?android:attr/borderlessButtonStyle"
- android:background="@drawable/shape_backgroundd"
- android:text="去抢"/>
- </LinearLayout>
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dip"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="13dp"
- android:background="#E0E0E0"/>
- </LinearLayout>
网络请求Adapter添加数据的更多相关文章
- 微信小程序教学第二章(含视频):小程序中级实战教程之预备篇 - 封装网络请求及 mock 数据
§ 封装网络请求及 mock 数据 本文配套视频地址: https://v.qq.com/x/page/i05544fogcm.html 开始前请把 ch2-3 分支中的 code/ 目录导入微信开发 ...
- ios MVVM实践 刷新网络请求+tableView展示数据
[实现效果] [目录结构相关] 此示例展示用的是MVVM结构形式,表述如下 M:数据Model的存储,可以用来对属性进行处理.(即胖model概念,上图中xx万人订阅这个处理方法写在Model内) V ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(2)
接着上一次的内容. 先说明一下关于split()方法:它通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串(把一个字符串分割成很多字符串组成的list列表) 语法: ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(4)
承接将查询城市编码的结果保存到文件中,以字典的形式保存,目的是为了在查询某个城市的天气的时候,能够通过输入的城市名称,找到对应的城市编码.所以此结果字典的数据结构,就是city={城市名称:城市编码} ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(3)
上节内容,是得到了省/直辖市编码,如web='http://m.weather.com.cn/data5/city01',我们需要继续获取此接口的数据,于是进行下面的操作 for i in b ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(5)
查询城市天气最后一节 需要导入上一节的结果city10.py #!/usr/bin/python# -*- coding: UTF-8 -*-import urllib.requestfrom ci ...
- Python 学习之urllib模块---用于发送网络请求,获取数据
1.urllib urllib是Python标准库的一部分,包含urllib.request,urllib.error,urllib.parse,urlli.robotparser四个子模块. (1) ...
- 阶段一:通过网络请求,获得并解析JSON数据(天气应用)
“阶段一”是指我第一次系统地学习Android开发.这主要是对我的学习过程作个记录. 在上一篇阶段一:解析JSON中提到,最近在写一个很简单的天气预报应用.即使功能很简单,但我还是想把它做成一个相对完 ...
- iOS开发——实战篇Swift篇&UItableView结合网络请求,多线程,数据解析,MVC实战
UItableView结合网络请求,多线程,数据解析,MVC实战 学了这么久的swift都没有做过什么东西,今天就以自己的一个小小的联系,讲一下,怎么使用swift在实战中应用MVC,并且结合后面的高 ...
随机推荐
- github/gitee使用办法
github/gitee只要添加SSH公钥都是可以连接上的 比如把某个文件上传gitee 首先肯定要有权限 否则会一直提醒failed伤心心 接下来说常用语句 git config --list ...
- 一 Struts框架(上)
Struts2 是基于MVC的WEB框架 经过六年多的发展,Struts1已经成为了一个高度成熟的框架,不管是稳定性还是可靠性都得到了广泛的证明.市场占有率超过20%,拥有丰富的开发人群,几乎已经成为 ...
- 让Mustache支持简单的IF语句
转载:https://blog.csdn.net/iteye_16732/article/details/82070065 Mustache是一种Logic-less templates.不支持if这 ...
- ubuntu10.04 32 编译android源码的问题
ubuntu10.04 32 问题 没有jdk1.6 并且使用apt-get 安装jdk相当麻烦,参照:http://blog.csdn.net/godvmxi/article/detail ...
- 【浅色】最强Win7 x64评测
[浅色]最强Win7 x64评测 [浅色]最强Win7 x86 & x64 | WINOS https://www.winos.me/archives/789.htmlESD671MB,安装后 ...
- C++Primer第五版——习题答案详解(五)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第6章 函数 练习6.4 #include<iostream> using ...
- greendao3.2.0使用
源代码地址 https://github.com/greenrobot/greenDAO buildscript { repositories { jcenter() mavenCentral() } ...
- studio--常见设置
13.Butterknife插件:zelezny 12.android studio怎么设置打开项目时打开项目列表? 11.stuido 代码背景颜色设置为护眼模式 ======== 13.But ...
- minicom 抓取log
使用minicom也有很长时间了,只用minicom抓过uart log,但是从来没有去保存过这个log,也不知道有这个功能.后来在超级终端中发现有这个功能(传送->捕获文字),想想minico ...
- 8、Curator的监听机制
原生的zookeeper的监听API所实现的方法存在一些缺点,对于开发者来说后续的开发会考虑的细节比较多. Curator所实现的方法希望摒弃原声API 的不足,是开发看起来更加的简单,一些重连等操作 ...