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;
}