English 中文(简体)
我如何利用拉齐·洛德来拉托语和基地。
原标题:How can I use LazyLoading with gallery and BaseAdapter?

我正在使用这一代码为美术馆创建<条码>BaseAdapter:

private class ImageAdapter extends BaseAdapter {

    /** The parent context */
    private Context myContext;

    /** URL-Strings to some remote images. */
    public String[] mImageURLs = {
    urlImage1,
    urlImage2,urlImage3,urlImage4,urlImage5,urlImage6,urlImage7};

    String [] myRemoteImages = {imageUrl,imageUrl2,imageUrl3,imageUrl4,imageUrl5,imageUrl6,imageUrl7};

    /** Simple Constructor saving the  parent  context. */
    public ImageAdapter(Context c) { this.myContext = c; }


    /** Returns the amount of images we have defined. */
    public int getCount() { 
    return this.myRemoteImages.length;
    }

    /* Use the array-Positions as unique IDs */
    public Object getItem(int position) {
    return position; 
    }

    public long getItemId(int position) {
    return position; 
    }

    /** Returns a new ImageView to
    * be displayed, depending on
    * the position passed. */
    public View getView(int position, View convertView, ViewGroup parent) {

    ImageView i = new ImageView(this.myContext);

    try {

        URL aURL = new URL(myRemoteImages[position]);
        Log.v("ImageLoader", "Remote images set");
        i.setTag(mImageURLs[position]);

        URI imageUri = null;
        SharedPreferences myPrefs = getSharedPreferences("imageUri", 0);
        SharedPreferences.Editor myPrefsEdit = myPrefs.edit();

        //Setting the Uri of aURL to imageUri.
        try {
            imageUri = aURL.toURI();
            myPrefsEdit.putString("uris", imageUri.toString());
            myPrefsEdit.commit();
        } catch (URISyntaxException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        //Testing to see if images are already in cache, if not then we load the images from the web and save them to the cache.
        if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists()) {
            Log.v("Loader", "File exists in cache. Now pulling from the cache");

            String cachFile = myContext.getCacheDir() +"/thumbnails/"+imageUri.hashCode();
            FileInputStream fis;

            try {
                fis = new FileInputStream(cachFile);
                Bitmap bm = BitmapFactory.decodeStream(fis);
                i.setImageBitmap(bm);

                i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                Log.v("Loader", "Image loaded from cache");

                /* Set the Width/Height of the ImageView. */
                if (Build.VERSION.SDK_INT >= 11) {
                    i.setLayoutParams(new Gallery.LayoutParams(450, 300));
                } else {
                    i.setLayoutParams(new Gallery.LayoutParams(200, 200));
                }      
            } catch (FileNotFoundException e) {    
                Log.e("DEBUGTAG", "Remtoe Image Exception", e);
            }

        //If images are not in cache... Here we download the images from the URL, and save them to cache.
        } else {
            Log.v("Loader", "Images are not in cache, Downloading images now....");
            URLConnection conn = aURL.openConnection();
            conn.setUseCaches(true);
            conn.connect();

            InputStream is = conn.getInputStream();
            /* Buffered is always good for a performance plus. */
            BufferedInputStream bis = new BufferedInputStream(is);
            /* Decode url-data to a bitmap. */
            Bitmap bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
            Log.v(imageUrl, "Retrieving image");

            /* Apply the Bitmap to the ImageView that will be returned. */

            i.setImageBitmap(bm);
            putBitmapInDiskCache(imageUri, bm);
            Log.v("Loader", "Image saved to cache");
            /* Set the Width/Height of the ImageView. */                                    
            if (Build.VERSION.SDK_INT >= 11) {
                i.setLayoutParams(new Gallery.LayoutParams(450, 300));
            }

我想要做的是,用拉齐里加固语,而不是在这里下载图像,然后将这些图像带给包裹。 它是lu淡和过于昂贵的。

As you can see I have the starter code above. How can I use LazyLoading with this?

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签