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

では、その場getView()で を作成する代わりにImageView、ImageView と TextView の両方を持つレイアウトをインフレートして、適切に入力することができます。

    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 に答える