//通过new一个自己定义的ViewHoladr 把数据保存在SetTag里面 convertView不为空时反复使用
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder=new ViewHolder();
if(convertView==null){
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.activity_item_app, null);
viewHolder.textView = convertView.findViewById(R.id.item_app_text);
viewHolder.imageView = convertView.findViewById(R.id.item_app_img);
convertView.setTag(viewHolder);
}else{
viewHolder=(ViewHolder)convertView.getTag();
}
//获取软件名称
String names = apps.get(position).activityInfo.loadLabel(getPackageManager()).toString();
viewHolder.textView.setText(names);
//获取软件图标
Drawable drawable = apps.get(position).activityInfo.loadIcon(getPackageManager());
viewHolder.imageView.setImageDrawable(drawable);
return convertView;
}
public class ViewHolder{
public ImageView imageView;
public TextView textView;
}