0

我可以通过图库适配器在图库中显示我的图像。现在,我需要为底部的每个图像添加标题。我不知道如何添加它。这是我的适配器代码:

    public class LensaPhotoAdapter_KM extends BaseAdapter{

    private int mGalleryItemBackground;

    private Context context;

    private ImageLoader imageLoader;
//  private File cacheDir;
    private ImageLoaderConfiguration config;
    private DisplayImageOptions options;
    private ArrayList<String> imageURLs = new ArrayList<String>();
    private ArrayList<String> imageTitle = new ArrayList<String>();


    public LensaPhotoAdapter_KM(Context context){
        Log.i("LensaPhotoAdapter", "Try to build the screen...");

        this.context = context;

        TypedArray attr = context.obtainStyledAttributes(R.styleable.HelloGallery);
        mGalleryItemBackground = attr.getResourceId(R.styleable.HelloGallery_android_galleryItemBackground, 0);
        attr.recycle();

        // Get singleton instance of ImageLoader
        imageLoader = ImageLoader.getInstance();
    }



    public void setData(ImageFeedItemList imageFeedItemList){
        int numberOfItems = imageFeedItemList.getHeaderImage().size();

        imageTitle = imageFeedItemList.getTitle();

//      for(String str: imageFeedItemList.getHeaderImage())
//          Log.i("title is:", str);

        for(int i=0; i<numberOfItems; i++){
            String str = imageFeedItemList.getTitle().get(i);
            str = str.substring(0, str.indexOf(" "));
            if(str.equalsIgnoreCase("Konsert"))
                imageURLs.add(imageFeedItemList.getHeaderImage().get(i));

//          for(String str1: imageURLs)
//              Log.i("title is:", str1);
        }

//      cacheDir = new File(Environment.getExternalStorageDirectory(), "UniversalImageLoader/Cache");

        // Create configuration for ImageLoader
        config = new ImageLoaderConfiguration.Builder(context)
                    .maxImageWidthForMemoryCache(800)
                    .maxImageHeightForMemoryCache(800)
                    .httpConnectTimeout(5000)
                    .httpReadTimeout(30000)
                    .threadPoolSize(5)
                    .threadPriority(Thread.MIN_PRIORITY + 2)
                    .denyCacheImageMultipleSizesInMemory()
                    .memoryCache(new UsingFreqLimitedMemoryCache(2000000)) // You can pass your own memory cache implementation
//                  .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
                    .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
                    .build();

        // Creates display image options for custom display task
        options = new DisplayImageOptions.Builder()
                    .showStubImage(R.drawable.icon_loading)
                    .showImageForEmptyUrl(R.drawable.icon_remove)
                    .cacheInMemory()
                    .cacheOnDisc()
                    .decodingType(DecodingType.MEMORY_SAVING)
                    .build();

        // Initialize ImageLoader with created configuration. Do it once.
        imageLoader.init(config);
    }



    //---returns the number of images---
    public int getCount() {
        return imageURLs.size();
    }

    //---returns the ID of an item--- 
    public Object getItem(int position) {
        return null;
    }

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

    //---returns an ImageView view---
    public View getView(int position, View convertView, ViewGroup parent){      
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new Gallery.LayoutParams(250, 250));
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setBackgroundResource(mGalleryItemBackground);

        // Load and display image
        String imageUrl = imageURLs.get(position);
        imageLoader.displayImage(imageUrl, imageView, options);

        return imageView;
    } 
} 

任何建议将不胜感激。谢谢

4

1 回答 1

1

在您的中,您可以扩展同时具有 ImageView 和 TextView 的布局getView(),而不是动态创建,然后您可以适当地填写:ImageView

    View container = inflater.inflate(R.layout.the_layout, parent, false);
    ImageView image = ll.findViewById(R.id.image);
    String imageUrl = imageURLs.get(position);
    imageLoader.displayImage(imageUrl, imageView, options);
    TextView text = ll.findViewById(R.id.text);
    text.setText("whatever");
于 2012-04-27T03:35:17.400 回答