这是我的问题:
Listview,显示我的设备上安装的应用程序列表(名称和图标)。 显示应用程序,但滚动时,元素重叠。
这是我的onCreate(活动):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//
final ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) pm
.queryIntentActivities(intent,
PackageManager.PERMISSION_GRANTED);
ApplicationsAdapter adapter = new ApplicationsAdapter(getApplicationContext(),R.id.lv_home, list, pm);
ListView lv = (ListView) findViewById(R.id.lv_home);
lv.setAdapter(adapter);
}
这是我的自定义适配器:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderListViewHome holder = null;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.list_item, parent, false);
holder = new ViewHolderListViewHome(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolderListViewHome) convertView.getTag();
}
final String text = mList.get(position).activityInfo.applicationInfo
.loadLabel(mPm).toString();
holder.applicationName = holder.getApplicationName();
holder.applicationName.setText(text);
final Drawable drawable = mList.get(position).activityInfo.applicationInfo
.loadIcon(mPm);
holder.applicationIcon = holder.getApplicationIcon();
holder.applicationIcon.setImageDrawable(drawable);
return convertView;
}
我想向您展示一张图片,但我没有所需的声誉,这些元素在向下滚动时会重叠。
提前感谢您的帮助:)
答案 0 :(得分:0)
假设您的ViewHolder是静态的。删除holder.applicationIcon = holder.getApplicationIcon()和类似的调用。只需使用holder.applicationIcon.setImageDrawable(drawable) - 为您的文本视图提供相同的建议。