我正在尝试创建一个自定义列表适配器,其中包含需要从Internet下载的每个项目的图像.当我第一次进入活动时 - 应用程序冻结一段时间,直到下载图像,然后加载活动列表.
我可以看出,在活动加载之前正在下载图像.如何在活动加载后下载图像.我想我需要使用Async Task.但由于我在自定义阵列适配器中加载图像,因此不确定如何操作.
这是我的自定义适配器getView()
:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.list_item_default, null);
}
Item p = items.get(position);
if (p != null) {
TextView list_title = (TextView) v.findViewById(R.id.list_title);
TextView list_description = (TextView) v
.findViewById(R.id.list_description);
TextView list_timestamp = (TextView) v
.findViewById(R.id.list_timestamp);
ImageView list_image = (ImageView) v.findViewById(R.id.list_image);
if (list_title != null) {
list_title.setText(p.getItemTitle());
}
if (list_description != null) {
list_description.setText(p.getItemDescription()); …
Run Code Online (Sandbox Code Playgroud)