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. java:file文件类

    public class FileDemo { public static File file; public static void main(String args[]) { String s = ...

  2. java: Comparable比较器,定义二叉操作类

    //定义二叉操作类 class BinaryTree{ class Node{ private Node left; //左指数 private Node right; //右指数 private C ...

  3. HANA 存储过程

    You can develop secure procedures using SQLScript in SAP HANA by observing the following recommendat ...

  4. 开始学Python

    怎么说,整体还是比较愚昧的.不知道该干什么,大学里学过C++,C语言,忘的差不多了.毕业了做的是SAP,自学过一段JAVA.总是东一榔头西一棒子,借口还是多. 那就说一些现状嘛,语言重在的是应用这个方 ...

  5. Windows下载安装虚拟机和CentOS7

    1,想要在Windows系统中安装linux系统,首先需要安装一个虚拟机VMware VMware 12下载地址:https://my.vmware.com/cn/web/vmware/info/sl ...

  6. rabbitmq_学习_00_资源帖

    一.精选资料 二.参考资料 1.RabbitMQ Simplest Queue 2.RabbitMQ系列教程 2.RabbitMQ入门教程 For Java[1] - Hello World 2.Ra ...

  7. poj3268 Silver Cow Party (SPFA求最短路)

    其实还是从一个x点出发到所有点的最短路问题.来和回只需分别处理一下逆图和原图,两次SPFA就行了. #include<iostream> #include<cstdio> #i ...

  8. Scala极速入门

    摘要 当面向对象遇到函数式编程,这就是Scala.简练的语言描述与简单的例子相辅相成,希望能够对大家学习Scala有所帮助. scala 入门 定义 Scala语言是一种面向对象语言,同时又结合了命令 ...

  9. visual assist(VA)设置快捷键(其它安装的插件设置快捷键也在这里)

    安装完visual assist后发现快捷键无法使用纠结,然后找如何去设置快捷建以此记录一下: 在Tools-->customize-->Keyboard-->Add-ins 常用的 ...

  10. The Great Mixing

    Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th typ ...