我获得了应用列表,但是我列入了这样的列表:[/ p>
第一次一切都很好,几次开始复制图标后:(
代码:
@Override
protected ArrayList<Order> doInBackground(String... params) {
PackageManager pm = getPackageManager();
appsList = new ArrayList<Order>();
Drawable img = null;
Intent intent;
try {
List<PackageInfo> packages = pm.getInstalledPackages(0);
for (int i = 0; i < packages.size(); i++) {
PackageInfo pi = packages.get(i);
ApplicationInfo ai = pi.applicationInfo;
intent = pm.getLaunchIntentForPackage(pi.packageName);
if(intent != null) {
img = ai.loadIcon(pm);
}
Order o = new Order();
o.setTextName(ai.loadLabel(pm).toString());
o.setTextPackageName(pi.packageName);
o.setTextVersion(pi.versionName);
o.setTextVersionCode(pi.versionCode);
o.setImage(img);
appsList.add(o);
};
} catch (Exception e) {
e.printStackTrace();
}
return appsList;
}
自定义适配器:
public class myAdapter extends ArrayAdapter<Order> {
private LayoutInflater lInflater;
private ArrayList<Order> data;
private Order o;
Context ctx;
Drawable noImage;
public myAdapter(Context c, int appsList, ArrayList<Order> data) {
super(c, appsList, data);
lInflater = LayoutInflater.from(c);
this.data = data;
ctx = c;
noImage = c.getResources().getDrawable(
R.drawable.ic_launcher);
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = lInflater.inflate(R.layout.custom_list, null);
holder = new ViewHolder();
holder.textName = (TextView) convertView
.findViewById(R.id.textName);
holder.textPackageName = (TextView) convertView
.findViewById(R.id.textPackageName);
holder.textVersion = (TextView) convertView
.findViewById(R.id.textVersion);
holder.textVersionCode = (TextView) convertView
.findViewById(R.id.textVersionCode);
holder.image = (ImageView) convertView.findViewById(R.id.imageLogo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
o = data.get(position);
holder.image.setTag(o);
if (o.getImage() == null) {
holder.image.setImageDrawable(noImage);
} else {
holder.image.setImageDrawable(o.getImage());
}
holder.textName.setText(o.getTextName());
holder.textName.setTextColor(Color.parseColor("#FFFFFF"));
holder.textPackageName.setText(o.getTextPackageName());
holder.textPackageName.setTextColor(Color.parseColor("#FFFFFF"));
holder.textVersion.setText("v." + o.gettTextVersion() + " ");
holder.textVersion.setTextColor(Color.parseColor("#2E64FE"));
holder.textVersionCode
.setText("v.c." + Integer.toString(o.getTextVersionCode()));
holder.textVersionCode.setTextColor(Color.parseColor("#01DFD7"));
holder.textName.setOnClickListener(new OnClickListener() {
int texTimetPos = position;
int textNamePos = position;
int linkPos = position;
@Override
public void onClick(View v) {
// Intent i = new Intent(getContext(), Details.class);
// i.putExtra("time",
// data.get(texTimetPos).getTextTime().toString());
// i.putExtra("name",
// data.get(textNamePos).getTextName().toString());
// i.putExtra("url",
// data.get(linkPos).getDetailsUrl().toString());
// ctx.startActivity(i);
}
});
return convertView;
}
static class ViewHolder {
TextView textName, textPackageName, textVersion, textVersionCode;
ImageView image;
}
我如何解决它?