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. WPF的Presenter(ContentPresenter)

    WPF的Presenter(ContentPresenter) 2010-12-20 14:34 by Clingingboy, 10619 阅读, 3 评论, 收藏, 编辑 这是2年前写了一篇文章 ...

  2. virualbox andirodx86

    背景 谷歌提供的andriod sdk模拟器在windows平台上很卡,是因为sdk是针对arm处理器架构的(就是嵌入式),而我们的windows系统是 x86架构 或者是 AMD架构,所以安卓模拟器 ...

  3. Windows 运行中的命令

    辅助功能选项 access.cpl 添加硬件向导 hdwwiz.cpl 添加或删除程序 appwiz.cpl 管理工具 control admintools 自动更新 wuaucpl.cpl Blue ...

  4. cocos2d-js 创建帧动画

    封装创建方法 var RunActionHelper = function(){ };RunActionHelper.prototype.createAnimationByPlist = functi ...

  5. hzau 1206 MathematicalGame

    1206: MathematicalGame Time Limit: 2 Sec  Memory Limit: 1280 MBSubmit: 124  Solved: 15[Submit][Statu ...

  6. 实现多层抽屉菜单,点击其中一项会动画打开该抽屉--第三方开源--MultiCardMenu

    下载地址:https://github.com/wujingchao/MultiCardMenu <net.wujingchao.android.view.MultiCardMenu xmlns ...

  7. bgcolor RGB 和16进制之间的转换,16进制转RGB,源码

    <p>bgcolor RGB 和16进制之间的转换,16进制转RGB,源码例如:<br /> 输入 201,255,201 转换成 #C9FFC9</p> < ...

  8. bzoj4513 储能表

    求 $\sum\limits_{i=0}^{n-1} \sum\limits_{j=0}^{m-1} max((x \space xor \space j) - k,0)$ ,膜 $p$ $n,m \ ...

  9. BZOJ - 2244 拦截导弹 (dp,CDQ分治+树状数组优化)

    题目链接 dp进阶之CDQ分治优化dp. 前置技能:dp基本功底,CDQ分治,树状数组. 问题等价于求二维最长上升子序列,是一个三维偏序问题(时间也算一维). 设$dp[i]=(l,x)$为以第i枚导 ...

  10. SpringMVC概要总结

    架构流程 1.  用户发送请求至前端控制器DispatcherServlet 2.  DispatcherServlet收到请求调用HandlerMapping处理器映射器. 3.  处理器映射器根据 ...