安卓ListView行详细内容展示页编写和下拉刷新实现
ListView行详细内容展示页:
使用轻量级的Fragment实现Listview行内容简单的详细信息展示:
值得注意的是:
1、 主布局(打开它的Activity)必须是FrameLayout布局(帧布局,上下叠加)
2、如果主布局的按钮不能被覆盖,则可在按钮属性加入:android:stateListAnimator="@null"
3、防止穿透点击可在Fragment类中找到视图后添加:view对象.setClickable(true);
4、如果使用的是import android.support.v4.app.Fragment;包时则操作使用getSupportFragmentManager,否则如果使用的是import android.app.Fragment;包时则操作使用getFragmentManager

Fragment类的布局编写:
<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" tools:context="com.example.httptest.ImgFragment"> <ImageView
android:layout_width="match_parent"
android:background="@color/colorBlack"
android:alpha="0.9"
android:layout_height="match_parent" /> <ImageView
android:layout_width="match_parent"
android:src="@mipmap/zcy4"
android:layout_gravity="center"
android:id="@+id/ff_img"
android:layout_height="match_parent" />
<TextView
android:layout_width="wrap_content"
android:text="图片展示页:" android:textSize="18dp"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:text="默认内容"
android:id="@+id/ff_title"
android:textColor="@color/colorRed"
android:layout_gravity="center|top"
android:layout_height="wrap_content" />
</FrameLayout>
Fragment类逻辑编写:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; /**
* A simple {@link Fragment} subclass.
*/
public class ImgFragment extends Fragment {
private ImageView imgview;
private TextView tv;
private int imgres;
private String text; //构造方法,传递内容和图片id参数
public ImgFragment(int imgres,String text) {
this.imgres=imgres;
this.text=text;
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View ffview=inflater.inflate(R.layout.fragment_img, container, false); //设置不能穿透点击
ffview.setClickable(true); imgview=(ImageView)ffview.findViewById(R.id.ff_img);
tv=(TextView)ffview.findViewById(R.id.ff_title); //显示
tv.setText(text);
imgview.setImageResource(imgres); return ffview;
} }
Activity的ListView监听事件里的部分代码:
基于上一篇的SimpleAdapter的事件监听
//得到内容
String cont=mMap.get("context").toString(); //得到图片资源
int img=(int)mMap.get("img"); //可自接通过此处改变控件上的某个图片显示
//图片显示控件,main_img=(ImageView)findViewById(R.id.main_img);
main_img.setImageResource(img); //开始Fragment
getSupportFragmentManager().beginTransaction()
.addToBackStack("xx1")
//参数1为主布局id,参数2中构造方法要传入图像资源和展示内容
.replace(R.id.main_view,new ImgFragment(img,cont))
.commit();
callbool=true;
Activity的返回和退出:
//物理返回键
//callbool标志位是为了先销毁Fragment,所以每次打开Fragment是都要设置callbool=true;
public void onBackPressed() {
// super.onBackPressed();关闭原有功能
if(callbool){
//将Fragment退栈
getSupportFragmentManager().popBackStack();callbool=false;
}
else {
//关闭程序
//MainActivity.this.finish();
System.exit(0);
}
}
Listview下拉刷新实现:
基于上一篇的BaseAdapt视图及数据实现
界面内容改变,套入SwipeRefreshLayout:
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:id="@+id/main_ref"
android:layout_marginTop="200dp"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:id="@+id/main_list"
android:layout_height="match_parent">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
必须设置此处:
设置为一个全局对象,不能每次数据获取都去建立新对象,否则需要每次初始化适配器类。
private List<BaseData> listdatax=new ArrayList<>();
刷新控件监听:
main_ref=(SwipeRefreshLayout)findViewById(R.id.main_ref);
//main_ref.setBackgroundResource(R.mipmap.zcy4);//listview的背景
main_ref.setProgressBackgroundColorSchemeColor(Color.RED);//刷新控件的背景 main_ref.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {//刷新监听
@Override
public void onRefresh() {
//清除list中存在的所有数据
if(listdatax.size()>0) listdatax.clear();
//已经省略重新获取数据
//.............
//在获取数据后重新调用适配器设置数据显示
main_list.setAdapter(myadapterx);
//在适配器类中设置数据完毕时,关闭动画
main_ref.setRefreshing(false);//关闭刷新动画 }
});
安卓ListView行详细内容展示页编写和下拉刷新实现的更多相关文章
- react-native-page-listview使用方法(自定义FlatList/ListView下拉刷新,上拉加载更多,方便的实现分页)
react-native-page-listview 对ListView/FlatList的封装,可以很方便的分页加载网络数据,还支持自定义下拉刷新View和上拉加载更多的View.兼容高版本Flat ...
- android124 zhihuibeijing 新闻中心-新闻 -北京页签 下拉刷新
缓存工具类:以url为key,json数据为value, package com.itheima.zhbj52.utils; import com.itheima.zhbj52.global.Glob ...
- 滚动到底部加载更多及下拉刷新listview的使用
最新内容建议直接访问原文:滚动到底部加载更多及下拉刷新listview的使用 本文主要介绍可同时实现下拉刷新及滑动到底部加载更多的ListView的使用. 该ListView优点包括:a. 可自定义下 ...
- android 项目学习随笔十一(ListView下拉刷新提示)
1. 设置mHeaderView.setPadding TOPPADING为负值,隐藏刷新提示头布局 在onTouchEvent事件中进行头布局显示隐藏切换 import java.text.Simp ...
- ListView下拉刷新,上拉自动加载更多
下拉刷新,Android中非常普遍的功能.为了方便便重写的ListView来实现下拉刷新,同时添加了上拉自动加载更多的功能.设计最初是参考开源中国的Android客户端源码.先看示例图. ...
- Android 自定义ListView实现底部分页刷新与顶部下拉刷新,androidlistview
在项目开发中,由于数据过大时,需要进行分页加载或下拉刷新,来缓解一次性加载的过长等待.本篇博文实例讲解通过自定义的ListView实现底部分页加载和顶部下拉刷新的效果. 其效果图: 一.ListVie ...
- vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件
vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件/库 一提到移动端的下拉刷新上拉翻页,你可能就会想到iScroll插件,没错iScroll是一个高性能,资源 ...
- Android 它们的定义ListView实现底部和页下拉刷新刷新的顶
在项目开发.由于数据量过大,寻呼需要加载或下拉刷新.为了缓解长期等待-time负载.这个博客的评论中被自己的定义实例ListView实现底部的下拉刷新页面正在加载结果和顶部. 其效果图: 一.List ...
- 安卓listView实现下拉刷新上拉加载滑动仿QQ的删除功能
大家对这些功能都是看的多了,然后对上拉刷新和下拉加载的原理都是非常清楚的,所以实现这功能其实也就是为了让大家能够从众多的同行们来进行比较学习而已,虽然即使是这样,但是面试的时候面试官还是会问你上拉和下 ...
随机推荐
- python 10 迭代器和三元运算符
一.迭代器 1.迭代器协议:对象必须提供一种next方法,执行该方法要么返回迭代中的下一项,要么引起一个stopIteration异常,终止迭代 2.可迭代对象:实现了迭代器协议的对象 3.pytho ...
- 第一二次java实训作业
1. 声明一个整型变量a,并赋初值5,在程序中判断a是奇数还是偶数,然后输出判断的结果. package java1; public class java1 { static int a=5; pub ...
- 20155312张竞予 Exp1 PC平台逆向破解(5)M
Exp1 PC平台逆向破解(5)M 目录 实验内容 手工修改可执行文件,改变程序执行流程,直接跳转到getShell函数. 利用foo函数的Bof漏洞,构造一个攻击输入字符串,覆盖返回地址,触发get ...
- String Match
Finding length of longest common substring /*Finding length of longest common substring using DP * * ...
- mysql时间戳转换
数据表中time是时间戳格式,转化成正常的时间格式 SELECT id,TIME,FROM_UNIXTIME(TIME,'%Y-%m-%d %H:%m:%S'),incline_id FROM inc ...
- 《Linux就该这么学》第十六天课程
今天笔记有点少就不发了,分享一下第23章 使用OpenLDAP部署目录服务很实用 下面是DHCP动态管理地址,如需深入学习请前往 https://www.linuxprobe.com/chapter- ...
- 2019.03.26 bzoj4446: [Scoi2015]小凸玩密室(树形dp)
传送门 题意简述: 给一棵完全二叉树,有点权aia_iai和边权,每个点有一盏灯,现在要按一定要求点亮: 任意时刻点亮的灯泡必须连通 点亮一个灯泡后必须先点亮其子树 费用计算如下:点第一盏灯不要花费 ...
- Spring Boot的应用启动器
Spring Boot应用启动器基本的一共有44种,具体如下: 1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring- ...
- 在Java中使用Socket模拟客户端和服务端(多线程)
1:Socket与ServerSocket的交互 2.Socket和ServerSocket介绍 Socket 构造函数 Socket() Socket(InetAddress address, in ...
- HTTP lab01 做一个简单的测试用 web页面
做一个简单的测试用 web页面 1.安装httpd服务 yum install httpd 安装完httpd服务后,系统就自动生成了/var/www/html目录 创建一个 ...