0

我想打开我的照片,设置为代表地址 (http) 的字符串。创建 SimpleAdapter 和他的传递字符串。

final ArrayList<HashMap<String,String>> CategoryList = UpdateMenuFromServer.getCategories();
final ListView ListCatalog = (ListView)findViewById(R.id.listView);
SimpleAdapter CatAdapter =new SimpleAdapter(this, CategoryList, R.layout.category_,
                    new String[] {"Name", "Image"},
                    new int[] {R.id.ProducerText, R.id.ProducerImage});

            ListCatalog.setAdapter(CatAdapter);

R.id.ProducerImage被处理了Class CustomImageView

public class CustomImageView extends ImageView{

    private static Context context;



    public CustomImageView(Context context) {
        super(context);
        this.context = context;
    }

    public CustomImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }
    public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
    }

    public void setImageURI (Uri uri1){
        try {
            URL url = new URL(uri1.toString());

            LoadImage load = new LoadImage(url);
            load.execute();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public class LoadImage extends AsyncTask<Void, Void, Drawable> {

        private URL Url;
        public LoadImage(URL url){
            Url = url;
        }
        @Override
        protected Drawable doInBackground(Void... voids) {
            Drawable ShowImage = null;
            try {
                ShowImage = Drawable.createFromStream(Url.openStream(), null);
            } catch (IOException e) {
                //e.printStackTrace();
            }

            return ShowImage;
        }

        protected void onPostExecute(Drawable ShowImage) {
            if(ShowImage!=null)
                setImageDrawable(ShowImage.getCurrent());
        }
    }
}

ListView 在加载第一个元素时看到它更改了所有图片,然后才加载其他元素。我的问题是如何避免它并加载 ListView 以打开我已经加载的图片。

4

0 回答 0