安卓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的删除功能
大家对这些功能都是看的多了,然后对上拉刷新和下拉加载的原理都是非常清楚的,所以实现这功能其实也就是为了让大家能够从众多的同行们来进行比较学习而已,虽然即使是这样,但是面试的时候面试官还是会问你上拉和下 ...
随机推荐
- 腾讯开源项目phxpaxos的编译步骤
#paxos的一般编译流程在项目文档<中文详细编译手册>里面已经有介绍,这里重点介绍一下编译samples目录下的代码: #我的环境是ubuntu; #设置paxos根目录 phx_dir ...
- PM学习梳理--建模型
- 【Python】 Python3 环境搭建
Python是一种计算机程序设计语言.是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项目的开发. Windo ...
- 谷歌浏览器运行Flash
最近有人问我谷歌浏览器的flash总是要点击手动运行才可以使用.看了很多网上很多教程,并没有比较好的解决方案. 自己找了相关资料后,找到了一个比较好的完整的.特此在这边放出来给大家使用. 新建记事本, ...
- oracle BLOG图片和CLOG base64码的转换
--BASE64转图片CREATE OR REPLACE FUNCTION DECODE_BASE64(P_CLOB_IN IN CLOB) RETURN BLOB IS V_BLOB BLOB; V ...
- Vue下载页面显示内容
摘抄自 https://www.cnblogs.com/zhangtianqi520/p/9323873.html 先下载所需依赖 npm install --save html2canvas npm ...
- 怎样用git上传代码到github以及如何更新代码
上传代码: 1.进入指定文件夹: cd 指定文件夹 2.初始化git仓库: git init 3.将项目所有文件添加到暂存区: git add . 4.提交到仓库: git commit -m &qu ...
- POI对Excel的操作
1. 先导包 commons-io-2.6.jar包,用于对文件的操作. 下载地址:http://commons.apache.org/proper/commons-io/download_io.cg ...
- SJCP认证题前五十题填坑
在做Java的SJCP认证试题时自己整理了一些Java基础细节知识点,以下是知识点陈列 1.标签机制:标签起作用的唯一的地方刚好在迭代语句之前(不然编译错误) continue label1 直接转到 ...
- C++ Error C2664:无法将参数 1 从“const char [9]”转换为“LPCWSTR”解决方案
问题出现 编译平台:VS2013 Windows 出现地方:在使用LoadLibrary( )函数动态链接DLL文件时出现的一个问题 Eg. 在使用 UNICODE字符的工程中, HIN ...