ListView---复杂的listview显示
1 . 初始化数据
private void fillData() {
ll_loading.setVisibility(View.VISIBLE); // 显示进度
new Thread() {
public void run() {
appInfos = AppInfoProvider.getAppInfos(AppManagerActivity.this); //得到所有的应用程序
userAppInfos = new ArrayList<AppInfo>(); //userAppinfos用户的应用程序
systemAppInfos = new ArrayList<AppInfo>(); //systemAppInfos系统的应用程序
for (AppInfo info : appInfos) { //遍历出所有的应用程序
if (info.isUserApp()) {
userAppInfos.add(info);
} else {
systemAppInfos.add(info);
}
}
// 加载listview的数据适配器
runOnUiThread(new Runnable() { // UI更新界面
@Override
public void run() {
if (adapter == null) {
adapter = new AppManagerAdapter(); // Adapter
lv_app_manager.setAdapter(adapter);
} else {
adapter.notifyDataSetChanged();
}
ll_loading.setVisibility(View.INVISIBLE); // 隐藏进度
}
});
};
}.start();
}
2.
private class AppManagerAdapter extends BaseAdapter { // 控制listview有多少个条目
@Override
public int getCount() {
// return appInfos.size();
return userAppInfos.size() + 1 + systemAppInfos.size() + 1;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
AppInfo appInfo;
if (position == 0) {// 显示的是用程序有多少个的小标签
TextView tv = new TextView(getApplicationContext());
tv.setTextColor(Color.WHITE);
tv.setBackgroundColor(Color.GRAY);
tv.setText("用户程序:" + userAppInfos.size() + "个");
return tv;
} else if (position == (userAppInfos.size() + 1)) {
TextView tv = new TextView(getApplicationContext());
tv.setTextColor(Color.WHITE);
tv.setBackgroundColor(Color.GRAY);
tv.setText("系统程序:" + systemAppInfos.size() + "个");
return tv;
} else if (position <= userAppInfos.size()) {// 用户程序
int newposition = position - 1;// 因为多了一个textview的文本占用了位置
appInfo = userAppInfos.get(newposition);
} else {// 系统程序
int newposition = position - 1 - userAppInfos.size() - 1;
appInfo = systemAppInfos.get(newposition);
}
View view;
ViewHolder holder; // if(position<userAppInfos.size()){//这些位置是留个用户程序显示的。
// appInfo = userAppInfos.get(position);
// }else{//这些位置是留个系统程序的。
// int newposition = position - userAppInfos.size();
// appInfo = systemAppInfos.get(newposition);
// }
if (convertView != null && convertView instanceof RelativeLayout) {
// 不仅需要检查是否为空,还要判断是否是合适的类型去复用
view = convertView;
holder = (ViewHolder) view.getTag();
} else {
view = View.inflate(getApplicationContext(),
R.layout.list_item_appinfo, null);
holder = new ViewHolder();
holder.iv_icon = (ImageView) view
.findViewById(R.id.iv_app_icon);
holder.tv_location = (TextView) view
.findViewById(R.id.tv_app_location);
holder.tv_name = (TextView) view.findViewById(R.id.tv_app_name);
holder.iv_status = (ImageView) view.findViewById(R.id.iv_status);
view.setTag(holder);
}
holder.iv_icon.setImageDrawable(appInfo.getIcon());
holder.tv_name.setText(appInfo.getName());
if (appInfo.isInRom()) {
holder.tv_location.setText("手机内存");
} else {
holder.tv_location.setText("外部存储");
}
if(dao.find(appInfo.getPackname())){
holder.iv_status.setImageResource(R.drawable.lock);
}else{
holder.iv_status.setImageResource(R.drawable.unlock);
}
return view;
} @Override
public Object getItem(int position) {
return null;
} @Override
public long getItemId(int position) {
return 0;
} } static class ViewHolder {
TextView tv_name;
TextView tv_location;
ImageView iv_icon;
ImageView iv_status;
}
3// 给listview注册一个滚动的监听器
lv_app_manager.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) { } // 滚动的时候调用的方法。
// firstVisibleItem 第一个可见条目在listview集合里面的位置。
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
dismissPopupWindow();
if (userAppInfos != null && systemAppInfos != null) {
if (firstVisibleItem > userAppInfos.size()) {
tv_status.setText("系统程序:" + systemAppInfos.size() + "个"); //list分类显示出:系统程序
} else {
tv_status.setText("用户程序:" + userAppInfos.size() + "个"); //list分类显示出:用户程序
}
}
}
});
附录: <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="55dip"
android:background="#8866ff00"
android:gravity="center"
android:text="软件管理器"
android:textColor="#000000"
android:textSize="22sp" /> <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/tv_avail_rom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="内存可用:"
android:textColor="#000000" /> <TextView
android:id="@+id/tv_avail_sd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="SD卡可用:"
android:textColor="#000000" />
</RelativeLayout> <FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <LinearLayout
android:id="@+id/ll_loading"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="invisible" > <ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="正在加载程序信息..." />
</LinearLayout> <ListView
android:id="@+id/lv_app_manager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fastScrollEnabled="true"
android:overScrollMode="never" >
</ListView> <TextView
android:id="@+id/tv_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff888888"
android:text="用户程序:6个"
android:textColor="#ffffff" />
</FrameLayout> </LinearLayout>
ListView---复杂的listview显示的更多相关文章
- [安卓] 16、ListView和GridView结合显示单元实现自定义列表显示效果
List在各种手机应用中都有体现,是安卓UI设计的必修课. 本文将介绍在开发中如何利用ListView和GridView设计自定义列表. 下面分别是用ListView和GridView做的效果: 上面 ...
- 看代码学知识之(2) ListView无数据时显示其他View
看代码学知识之(2) ListView无数据时显示其他View 今天看的一块布局是这样的: <!-- The frame layout is here since we will be show ...
- android listView多层嵌套listView显示不全问题
最近在做项目,需要用到listVIew多层嵌套listVIew的需求,先发现已下两个处理办法比较好用 第一种: public class ListViewNesting extends ListVie ...
- 解决ScrollView中包含ListView,导致ListView显示不全
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- ScrollView中嵌套ListView时,listview高度显示的问题
方法一:直接更改listview的控件高度,动态获取(根据条目和每个条目的高度获取) 前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个Lis ...
- Android基本控件之listView(三)<用ListView实现分页加载>
我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...
- Android进阶笔记14:ListView篇之ListView性能优化
1. 首先思考一个问题ListView如何才能提高效率 ? 当convertView为空时候,用setTag()方法为每个View绑定一个存放控件的ViewHolder对象.当convertView不 ...
- Android如何在ListView中嵌套ListView
前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...
- 项目中那些事|ListView中嵌套ListView问题
要在一个ListView中放入另一个ListView,也即在一个ListView的每个 item 中放入另外一个ListView.但刚开始的时候,会发现放入的子ListView会显示不完全(我这里只显 ...
- 在ListView中嵌套ListView的事件处理
十分感谢此作者,以及作者的作者,让我卡了一星期的问题解决了!!http://blog.csdn.net/hutengfei0701/article/details/8956284谢谢http://my ...
随机推荐
- 选择排序—简单选择排序(Simple Selection Sort)原理以及Java实现
基本思想: 在要排序的一组数中,选出最小(或者最大)的一个数与第1个位置的数交换:然后在剩下的数当中再找最小(或者最大)的与第2个位置的数交换,依次类推,直到第n-1个元素(倒数第二个数)和第n个元素 ...
- 33 python 并发编程之IO模型
一 IO模型介绍 为了更好地了解IO模型,我们需要事先回顾下:同步.异步.阻塞.非阻塞 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非 ...
- Mybatis_总结_06_用_插件开发
一.前言 Mybatis采用责任链模式,通过动态代理组织多个插件(拦截器),通过这些插件可以改变Mybatis的默认行为(诸如SQL重写之类的),由于插件会深入到Mybatis的核心,因此在编写自己的 ...
- "Cannot declare member function ...to have static linkage"错误
英文解释: if you declare a method to be static in your .cc file. The reason is that static means somethi ...
- CodeForces - 651D:Image Preview (双指针&)
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
- LeetCode Construct String from Binary Tree
原题链接在这里:https://leetcode.com/problems/construct-string-from-binary-tree/#/description 题目: You need t ...
- MongoDB数据库的备份和恢复
MongoDB数据库备份方式: 1.整库备份 2.单表备份 1.整库备份 备份整个数据库: mongodump -h 127.0.0.1:27000 -d park --authenticationD ...
- HUD2102(基础bfs)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 侯捷STL学习(三)--分配器测试
第七节:分配器测试 标准的分配器Allocator,#include<ext/...>都是拓展的 可以用不同的分配器测试同一容器 分配器allocate() & deallocat ...
- IDA Pro权威指南学习笔记(一)
一直不懂逆向,最近刚好不忙,于是学习逆向,用来做笔记,顺便和大家分享交流. 参考书籍<IAD PRO权威指南> 工具: PETools: ETools 是另一款很好的PE文件编辑工具,以前 ...