Exemplo n.º 1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      if (position == 0) {
        TextView textView = new TextView(AppManagerActivity.this);

        textView.setBackgroundColor(Color.LTGRAY);
        textView.setText("user app:" + userApp.size());
        return textView;
      } else if (position == userApp.size() + 1) {
        TextView textView = new TextView(AppManagerActivity.this);

        textView.setBackgroundColor(Color.LTGRAY);
        textView.setText("system app:" + systemApp.size());
        return textView;
      }
      // get block list object
      final AppInfo info;
      if (position < userApp.size() + 1) {
        info = userApp.get(position - 1);
      } else {
        info = systemApp.get(position - userApp.size() - 1 - 1);
      }

      final ViewHolder holder;

      if (convertView != null && convertView instanceof LinearLayout) {
        holder = (ViewHolder) convertView.getTag();
      } else {
        convertView = View.inflate(AppManagerActivity.this, R.layout.listview_item_app, null);

        holder = new ViewHolder();
        holder.iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
        holder.tv_app_name = (TextView) convertView.findViewById(R.id.tv_app_name);
        holder.tv_version_size = (TextView) convertView.findViewById(R.id.tv_version_size);
        holder.iv_uninstall = (ImageView) convertView.findViewById(R.id.iv_uninstall);
        convertView.setTag(holder);
      }

      String apkName = info.getApkName();
      holder.tv_app_name.setText(apkName);

      String tv_version_size = info.getVersion() + ", " + info.getSize();
      holder.tv_version_size.setText(tv_version_size);

      Drawable drawable = info.getIcon();
      holder.iv_icon.setImageDrawable(drawable);

      holder.iv_uninstall.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Intent intent =
                  new Intent(
                      "android.intent.action.DELETE",
                      Uri.parse("package:" + info.getPackageName()));
              startActivity(intent);
            }
          });

      return convertView;
    }