安卓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的删除功能
		
大家对这些功能都是看的多了,然后对上拉刷新和下拉加载的原理都是非常清楚的,所以实现这功能其实也就是为了让大家能够从众多的同行们来进行比较学习而已,虽然即使是这样,但是面试的时候面试官还是会问你上拉和下 ...
 
随机推荐
- luogu||P1776||宝物筛选||多重背包||dp||二进制优化
			
题目描述 终于,破解了千年的难题.小FF找到了王室的宝物室,里面堆满了无数价值连城的宝物……这下小FF可发财了,嘎嘎.但是这里的宝物实在是太多了,小FF的采集车似乎装不下那么多宝物.看来小FF只能含泪 ...
 - python基础之Day18
			
一.序列化概念 什么是序列化? 内存中的数据结构转成中间格式(json(所有编程语言通用)和pickle)存储到硬盘或基于网络状态 反序列化: 硬盘网络传来的数据格式转换成内存的数据结构 为什么 1. ...
 - linux学习第十五天 (Linux就该这么学) 找到一本不错的Linux电子书,附《Linux就该这么学》章节目录
			
今天收尾DNS内容复习了,还有分享解析配置,都没有记,主要访问同一个域名,就近访问,
 - Maven 属性
			
maven 中使用 ${属性名} 来访问属性 内置属性 (maven 预定义,用户可以直接使用的属性) ${basedir} 表示项目根目录,即包含 pom.xml 文件的目录.同 ${projec ...
 - GUI学习之五——QAbstractButton类学习笔记
			
今天总结一下AbstractButton类的学习笔记. 一.描述 AbstractButton是对各种按键的抽象类他的继承关系是这样的 首先,QAbstractButton继承了QWidget类的各种 ...
 - 数据库database
			
1.创建数据库:create datebase financials create database if not exists financilas 2.查看数据库(所有): show da ...
 - AX_DataSource
			
for (custInvoiceJourLocal = custInvoiceJour_ds.getFirst(true) ? custInvoiceJour_ds.getFirst(true) : ...
 - Java容器-个人整理1
			
1.初始化集合时,若能知道知道容量,尽量初始化时确定容量.容器类一般可以自动扩充,但扩充是有性能代价的. 2.Arrays.asList()的底层表示仍然时数组,因此不能进行调整尺寸的操作. 3.Ha ...
 - 02.02.03第3章 餐饮项目案例(Power BI商业智能分析)
			
02.02.03第3章 餐饮项目案例 02.02.03.01餐饮数据理解与读入 00:06:12 02.02.03.02餐饮数据处理 00:29:57 处理生成的表为: 02.02.03.03餐饮数据 ...
 - java中的抽象类的作用
			
抽象函数的作用有很多,我就举一个例子,(mars老师的例子): 打印机: 父类---Printer 子类---HBPrinter 子类----CanonPrinter 测试类----Test //定义 ...