zoukankan      html  css  js  c++  java
  • android项目复杂的listview

        private class AppAdapter extends BaseAdapter {
    
            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return userApp.size()+sysApp.size()+2;
            }
    
            @Override
            public Object getItem(int arg0) {
                // TODO Auto-generated method stub
                return arg0;
            }
    
            @Override
            public long getItemId(int arg0) {
                // TODO Auto-generated method stub
                return arg0;
            }
    
            @Override
            public View getView(int position, View arg1, ViewGroup arg2) {
                AppInfo app ;
                //判断当前位置是不是第一个,如果是返回出去一个textview
                if (position==0) {
                    TextView tv = new TextView(AppManagerActivity.this);
                    tv.setText("用户程序("+userApp.size()+")");
                    tv.setTextColor(Color.WHITE);
                    return tv;
                    //判断当前位置是不是用来显示下一个textview的位置,就是用户程序集合+1
                }else if(position==userApp.size()+1){
                    TextView tv = new TextView(AppManagerActivity.this);
                    tv.setText("系统程序("+sysApp.size()+")");
                    tv.setTextColor(Color.WHITE);
                    return tv;
                    //判断位置是不是用来显示用户程序的位置
                }else if(position<=userApp.size()){
                    app = userApp.get(position-1);
                    //最后就是用来显示系统程序的位置
                }else{
                    app = sysApp.get(position-userApp.size()-2);
                }
                    
                
                View v = null;
                ViewHolder viewHolder = null;
                //进行校验,缓存必须是linearlayout的子类,
                if (arg1 != null&&arg1 instanceof LinearLayout) {
                    v = arg1;
                    viewHolder = (ViewHolder) v.getTag();
    
                } else {
                    v = View.inflate(AppManagerActivity.this,
                            R.layout.item_app_show, null);
                    viewHolder = new ViewHolder();
                    viewHolder.tv_name = (TextView) v
                            .findViewById(R.id.app_item_tv_name);
                    viewHolder.tv_location = (TextView) v
                            .findViewById(R.id.app_item_tv_location);
                    viewHolder.img_icon = (ImageView) v
                            .findViewById(R.id.app_item_img_icon);
                    // 对应关系一致
                    v.setTag(viewHolder);
                }
                viewHolder.img_icon.setImageDrawable(app.getIcon());
                viewHolder.tv_name.setText(app.getName());
                if (app.isRow()) {
                    viewHolder.tv_location.setText("内部存储程序");
                } else {
                    viewHolder.tv_location.setText("外部存储程序");
                }
                return v;
            }
    
        }
    
        static class ViewHolder {
            ImageView img_icon;
            TextView tv_name;
            TextView tv_location;
        }
  • 相关阅读:
    Linux下安装jdk
    hadoop下载
    Java:xxx is not an enclosing class
    Android:Gradle报错——No resource found that matches the given name (at 'dialogCornerRadius' with value '?android:attr/dialogCornerRadius')
    TensorFlow:在PyCharm中配置TensorFlow
    Android:屏幕旋转
    Android:onActivityResult详解
    Android:Bundle类
    Android:ConstraintLayout完全解析
    Android:Android Studio生成签名文件,自动签名,以及获取SHA1和MD5值
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/5030744.html
Copyright © 2011-2022 走看看