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显示的更多相关文章

  1. [安卓] 16、ListView和GridView结合显示单元实现自定义列表显示效果

    List在各种手机应用中都有体现,是安卓UI设计的必修课. 本文将介绍在开发中如何利用ListView和GridView设计自定义列表. 下面分别是用ListView和GridView做的效果: 上面 ...

  2. 看代码学知识之(2) ListView无数据时显示其他View

    看代码学知识之(2) ListView无数据时显示其他View 今天看的一块布局是这样的: <!-- The frame layout is here since we will be show ...

  3. android listView多层嵌套listView显示不全问题

    最近在做项目,需要用到listVIew多层嵌套listVIew的需求,先发现已下两个处理办法比较好用 第一种: public class ListViewNesting extends ListVie ...

  4. 解决ScrollView中包含ListView,导致ListView显示不全

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  5. ScrollView中嵌套ListView时,listview高度显示的问题

    方法一:直接更改listview的控件高度,动态获取(根据条目和每个条目的高度获取) 前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个Lis ...

  6. Android基本控件之listView(三)<用ListView实现分页加载>

    我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...

  7. Android进阶笔记14:ListView篇之ListView性能优化

    1. 首先思考一个问题ListView如何才能提高效率 ? 当convertView为空时候,用setTag()方法为每个View绑定一个存放控件的ViewHolder对象.当convertView不 ...

  8. Android如何在ListView中嵌套ListView

    前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...

  9. 项目中那些事|ListView中嵌套ListView问题

    要在一个ListView中放入另一个ListView,也即在一个ListView的每个 item 中放入另外一个ListView.但刚开始的时候,会发现放入的子ListView会显示不完全(我这里只显 ...

  10. 在ListView中嵌套ListView的事件处理

    十分感谢此作者,以及作者的作者,让我卡了一星期的问题解决了!!http://blog.csdn.net/hutengfei0701/article/details/8956284谢谢http://my ...

随机推荐

  1. jsp:jstl标签之控制流程

    下面将要讲的用于流程控制的标签,其中包括:if.choose.when 与 otherwise 等.接下来对这些标签逐一讲解. 这个标签的作用和 Java 程序中的 if 语句作用相同,用于判断条件语 ...

  2. IIS7 配置PHP服务器

    安装PHP Manager: 1)访问 http://phpmanager.codeplex.com/releases/view/69115 下载PHP Manager.其中,x86 为32位 Win ...

  3. poj3694 边-双连通分量+lca

    题意:先给了一张无向图,然后依次加边,每次求桥的数量 题解:先用一次tarjan,我们可以标记桥的位置和记录桥的数量同时记录fa数组,然后更新边的时候我们可以用lca,因为在tarjan缩点之后得到了 ...

  4. leetcode 645. Set Mismatch——凡是要节约空间的题目 都在输入数据上下功夫 不要担心破坏原始的input

    The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...

  5. 用lsmod看硬盘驱动决定是sata还是scsi盘

    sas盘 scsi盘 sata盘都是显示为sdx的所以无法区别唯一可以分别的是看看内核加载的驱动模块有啥 lsmod....mptsas      62545       7

  6. SQL多表联查总结

    交叉连接:(不常用)返回两个表的笛卡尔乘积(也即全组合排列)中符合查询条件的数据行. 内连接返回连接表中符合连接条件和查询条件的数据行. 左外连接返回符合连接条件和查询条件(即:内连接)的数据行,且还 ...

  7. BZOJ - 2142 礼物 (扩展Lucas定理)

    扩展Lucas定理模板题(貌似这玩意也只能出模板题了吧~~本菜鸡见识鄙薄,有待指正) 原理: https://blog.csdn.net/hqddm1253679098/article/details ...

  8. 隐藏select中的“请选择”项

    <select> <option value="" style="display: none">请选择</option> & ...

  9. centos安装yum源

    网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错,将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本无法找到.具体设置方法如下 ...

  10. 0. LeetCode 开篇

    LeetCode 开篇 很久以前(也许是几天之前,记忆力没那么好),听朋友说过,但是没怎么重视,最近发现自己基础打的不牢(会是会,但是说不出来,说不明白),故借此机会理一理知识点,并复习,巩固相关知识 ...