【发布时间】:2014-02-13 12:22:09
【问题描述】:
我正在开发一个新的 Home Launcher,目前它使用列表视图来显示已安装的应用程序。我正在使用自定义适配器来提供应用程序名称和图标。如果我留下应用程序名称,我没有问题,但是,如果我添加图标,列表视图会变得非常缓慢且无法使用。我也尝试过 asynctask,但没有运气。这是我的适配器的相关图片:
public AppInfoAdapter(Context c, List list, ArrayList<String> appList, PackageManager pm, Resources resources) {
mContext = c;
mListAppInfo = list;
mPackManager = pm;
mAppList = appList;
mResources = resources;
activity = (Activity) c;
}
=====
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
v = inflater.inflate(R.layout.launcher_adapter_row, null);
}
if (v != null) {
mIcon = (ImageView) v.findViewById(R.id.imageView1);
tvAppName = (TextView) v.findViewById(R.id.textView1);
}
new addItems().execute(tvAppName, mIcon, position);
return v;
}
====
public class addItems extends AsyncTask<Object, String, Void> {
private TextView title;
private ImageView icon;
private int pos;
@Override
protected Void doInBackground(final Object... parameters) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
title = (TextView) parameters[0];
icon = (ImageView) parameters[1];
pos = (Integer) parameters[2];
entry = (ApplicationInfo) mListAppInfo.get(pos);
icon.setImageDrawable(entry.loadIcon(mPackManager));
title.setText(entry.loadLabel(mPackManager));
}
});
return null;
}
}
尝试使用列表视图和网格视图。结果是一样的。由于口吃,滚动是完全不可能的。有什么建议?谢谢
【问题讨论】:
标签: android android-listview android-asynctask android-adapter baseadapter