A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© woshiku 中级黑马   /  2015-9-10 08:56  /  473 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.woshiku.deleapp.adapter;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.text.format.Formatter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.woshikju.deleapp.R;
import com.woshiku.deleapp.domian.AppInfo;
import com.woshiku.deleapp.domian.ViewHolder;
public class ManagerAppAdapter extends BaseAdapter {
        Context context;
        private ArrayList<AppInfo> userAppInfos,systemAppInfos;
        public ManagerAppAdapter(Context context,List<AppInfo> userAppInfos,List<AppInfo> systemAppInfos){
                this.context = context;
                this.userAppInfos = (ArrayList<AppInfo>) userAppInfos;
                this.systemAppInfos = (ArrayList<AppInfo>) systemAppInfos;
        }
        @Override
        public int getCount() {
                // TODO Auto-generated method stub
                return userAppInfos.size()+1+systemAppInfos.size()+1;
        }
        @Override
        public Object getItem(int position) {
                // TODO Auto-generated method stub
                if (position == 0) {
            return null;
        } else if (position == userAppInfos.size() + 1) {
            return null;
        }
        AppInfo appInfo;
        if (position < userAppInfos.size() + 1) {
            //把多出来的特殊的条目减掉
            appInfo = userAppInfos.get(position - 1);
        } else {
            int location = userAppInfos.size() + 2;
            appInfo = systemAppInfos.get(position - location);
        }
        return appInfo;
        }

        @Override
        public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                ViewHolder viewHolder = null;
                if(position==0){
                        TextView textView = new TextView(context);
                        textView.setTextColor(Color.WHITE);
            textView.setBackgroundColor(Color.GRAY);
            textView.setText("用户程序(" + userAppInfos.size() + ")");
            return textView;
                }else if(position == userAppInfos.size()+1){
                        TextView textView = new TextView(context);
                        textView.setTextColor(Color.WHITE);
            textView.setBackgroundColor(Color.GRAY);
            textView.setText("系统程序(" + systemAppInfos.size() + ")");
            return textView;
                }
                AppInfo appInfo;
                if(position<=userAppInfos.size()){
                        appInfo = userAppInfos.get(position-1);
                }else{
                        appInfo = systemAppInfos.get(position-userAppInfos.size()-2);
                }
                if(convertView != null&& convertView instanceof LinearLayout){
                        viewHolder = (ViewHolder)convertView.getTag();
                }else{
                        convertView = View.inflate(context, R.layout.manage_app_list_item, null);
                        viewHolder = new ViewHolder();
                        viewHolder.app_name = (TextView)convertView.findViewById(R.id.app_name);
                        viewHolder.app_size = (TextView)convertView.findViewById(R.id.app_size);
                        viewHolder.app_source = (TextView)convertView.findViewById(R.id.app_source);
                        viewHolder.app_icon = (ImageView)convertView.findViewById(R.id.app_icon);
                        convertView.setTag(viewHolder);
                }
//                if(convertView == null){
//                        convertView = View.inflate(context, R.layout.manage_app_list_item, null);
//                        viewHolder = new ViewHolder();
//                        viewHolder.app_name = (TextView)convertView.findViewById(R.id.app_name);
//                        viewHolder.app_size = (TextView)convertView.findViewById(R.id.app_size);
//                        viewHolder.app_source = (TextView)convertView.findViewById(R.id.app_source);
//                        viewHolder.app_icon = (ImageView)convertView.findViewById(R.id.app_icon);
//                        convertView.setTag(viewHolder);
//                }else{
//                        viewHolder = (ViewHolder)convertView.getTag();
//                }
                viewHolder.app_name.setText(appInfo.getAppName());
                viewHolder.app_size.setText(Formatter.formatFileSize(context,appInfo.getAppSize() ));
                if(appInfo.isAppRom()){
                        viewHolder.app_source.setText("手机内存");
                }else{
                        viewHolder.app_source.setText("SD卡");
                }
                viewHolder.app_icon.setBackgroundDrawable(appInfo.getAppIcon());
                return convertView;
        }

}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马