安卓ListView行详细内容展示页编写和下拉刷新实现

安卓ListView行详细内容展示页编写和下拉刷新实现,第1张

概述ListView行详细内容展示页: 使用轻量级的Fragment实现Listview行内容简单的详细信息展示: 值得注意的是: 1、 主布局(打开它的Activity)必须是FrameLayout布局

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类的布局编写:

 1 <FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" 2     xmlns:tools="http://schemas.androID.com/tools" 3     androID:layout_wIDth="match_parent" 4     androID:layout_height="match_parent" 5  6     tools:context="com.example.httptest.imgFragment"> 7  8 <ImageVIEw 9     androID:layout_wIDth="match_parent"10     androID:background="@color/colorBlack"11     androID:Alpha="0.9"12     androID:layout_height="match_parent" />13 14     <15         androID:layout_wIDth="match_parent"16         androID:src="@mipmap/zcy4"17         androID:layout_gravity="center"18         androID:ID="@+ID/ff_img"19         androID:layout_height="match_parent" />20     <TextVIEw21         androID:layout_wIDth="wrap_content"22         androID:text="图片展示页:"23 24         androID:textSize="18dp"25         androID:layout_height="wrap_content" />26 27     <28         androID:layout_wIDth="wrap_content"29         androID:layout_margintop="20dp"30         androID:text="默认内容"31         androID:ID="@+ID/ff_Title"32         androID:textcolor="@color/colorRed"33         androID:layout_gravity="center|top"34         androID:layout_height="wrap_content" />35 </FrameLayout>

Fragment类逻辑编写:

 1 import androID.os.Bundle; 2  androID.support.v4.app.Fragment; 3  androID.vIEw.LayoutInflater; 4  androID.vIEw.VIEw; 5  androID.vIEw.VIEwGroup; 6  androID.Widget.ImageVIEw; 7  androID.Widget.TextVIEw; 8  9 10 /**11  * A simple {@link Fragment} subclass.12  */13 public class imgFragment extends Fragment {14     private ImageVIEw imgvIEw;15      TextVIEw tv;16     private int imgres;17      String text;18 19     //构造方法,传递内容和图片ID参数20     public imgFragment( imgres,String text) {21         this.imgres=imgres;22         this.text=text;23     }24 25 26     @OverrIDe27     public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,28                              Bundle savedInstanceState) {29         VIEw ffvIEw=inflater.inflate(R.layout.fragment_img,container,false);30 31         设置不能穿透点击32         ffvIEw.setClickable(true33 34         imgvIEw=(ImageVIEw)ffvIEw.findVIEwByID(R.ID.ff_img);35         tv=(TextVIEw)ffvIEw.findVIEwByID(R.ID.ff_Title);36 37         显示38         tv.setText(text);39         imgvIEw.setimageResource(imgres);40 41         return ffvIEw;42 43 44 }

Activity的ListVIEw监听事件里的部分代码:

基于上一篇的SimpleAdapter的事件监听

得到内容 2 String cont=mMap.get("context").toString(); 3 得到图片资源int img=(int)mMap.get("img" 6 可自接通过此处改变控件上的某个图片显示 8 图片显示控件,main_img=(ImageVIEw)findVIEwByID(R.ID.main_img); 9 main_img.setimageResource(img);10 开始Fragment12 getSupportFragmentManager().beginTransaction()13         .addToBackStack("xx1")14         参数1为主布局ID,参数2中构造方法要传入图像资源和展示内容15         .replace(R.ID.main_vIEw,1)">new imgFragment(img,cont))16         .commit();17 callbool=true;

Activity的返回和退出:

物理返回键callbool标志位是为了先销毁Fragment,所以每次打开Fragment是都要设置callbool=true;voID onBackpressed() { 4      super.onBackpressed();关闭原有功能 5  if(callbool){ 6      将Fragment退栈 7         getSupportFragmentManager().popBackStack();callbool=; 9     else {10         关闭程序11         MainActivity.this.finish();12          System.exit(0 }14     }

 

ListvIEw下拉刷新实现:

基于上一篇的BaseAdapt视图及数据实现

界面内容改变,套入SwipeRefreshLayout:

 1 <androID.support.v4.Widget.SwipeRefreshLayout 2     androID:layout_wIDth="match_parent" 3     androID:ID="@+ID/main_ref" 4     androID:layout_margintop="200dp" 5     androID:layout_height="match_parent"> 6     <ListVIEw 7         androID:layout_wIDth="match_parent" 8         androID:ID="@+ID/main_List" 9         androID:layout_height="match_parent">10     </ListVIEw>11 </androID.support.v4.Widget.SwipeRefreshLayout>

必须设置此处:

设置为一个全局对象,不能每次数据获取都去建立新对象,否则需要每次初始化适配器类。

private  List<BaseData> Listdatax=new ArrayList<>();

刷新控件监听:

 1 main_ref=(SwipeRefreshLayout)findVIEwByID(R.ID.main_ref);main_ref.setBackgroundResource(R.mipmap.zcy4);ListvIEw的背景 3 main_ref.setProgressBackgroundcolorSchemecolor(color.RED);刷新控件的背景 4  5 main_ref.setonRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {刷新监听 7      onRefresh() { 8         清除List中存在的所有数据 9         if(Listdatax.size()>0) Listdatax.clear();已经省略重新获取数据.............12         在获取数据后重新调用适配器设置数据显示        main_List.setAdapter(myadapterx);在适配器类中设置数据完毕时,关闭动画15         main_ref.setRefreshing(false);关闭刷新动画16 17 18 });

 

 

总结

以上是内存溢出为你收集整理的安卓ListView行详细内容展示页编写和下拉刷新实现全部内容,希望文章能够帮你解决安卓ListView行详细内容展示页编写和下拉刷新实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1121209.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存