标签:
int lastVisiblePosition = view.getLastVisiblePosition(); |
private class TaskManagerAdapter extends BaseAdapter {
private static final String TAG = "TaskManagerAdapter";
@Override
public int getCount() {
SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
if (sp.getBoolean("showsystem", false)) {
return userTaskInfos.size() + 1 + systemTaskInfos.size() + 1;
}else{
return userTaskInfos.size() + 1 ;
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TaskInfo taskInfo;
if (position == 0) {// 用户进程的标签
TextView tv = new TextView(getApplicationContext());
tv.setBackgroundColor(Color.GRAY);
tv.setTextColor(Color.WHITE);
tv.setText("用户进程:" + userTaskInfos.size() + "个");
return tv;
} else if (position == (userTaskInfos.size() + 1)) {
TextView tv = new TextView(getApplicationContext());
tv.setBackgroundColor(Color.GRAY);
tv.setTextColor(Color.WHITE);
tv.setText("系统进程:" + systemTaskInfos.size() + "个");
return tv;
} else if (position <= userTaskInfos.size()) {
taskInfo = userTaskInfos.get(position - 1);
} else {
taskInfo = systemTaskInfos.get(position - 1
- userTaskInfos.size() - 1);
}
View view;
ViewHolder holder;
if (convertView != null && convertView instanceof RelativeLayout) {
view = convertView;
holder = (ViewHolder) view.getTag();
Log.i(TAG, "复用缓存。。" + position);
} else {
view = View.inflate(getApplicationContext(),
R.layout.list_item_taskinfo, null);
holder = new ViewHolder();
holder.iv_icon = (ImageView) view
.findViewById(R.id.iv_task_icon);
holder.tv_name = (TextView) view
.findViewById(R.id.tv_task_name);
holder.tv_memsize = (TextView) view
.findViewById(R.id.tv_task_memsize);
holder.cb_status = (CheckBox) view.findViewById(R.id.cb_status);
view.setTag(holder);
Log.i(TAG, "创建新的view对象" + position);
}
holder.iv_icon.setImageDrawable(taskInfo.getIcon());
holder.tv_name.setText(taskInfo.getName());
holder.tv_memsize.setText("内存占用:"
+ Formatter.formatFileSize(getApplicationContext(),
taskInfo.getMemsize()));
holder.cb_status.setChecked(taskInfo.isChecked());
if (getPackageName().equals(taskInfo.getPackname())) {
holder.cb_status.setVisibility(View.INVISIBLE);
} else {
holder.cb_status.setVisibility(View.VISIBLE);
}
return view;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
static class ViewHolder {
ImageView iv_icon;
TextView tv_name;
TextView tv_memsize;
CheckBox cb_status;
}
标签:
原文地址:http://www.cnblogs.com/linmbbest/p/4762760.html