2012-04-27 2 views
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; 
    } 
} 

모든 의견을 환영합니다. 감사합니다

당신의 getView()에서

답변

1

대신 비행에 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"); 
+0

당신이 악마 감사를, 사실 내가 전에 이런 식으로했고 결과는 괜찮습니다. 하지만 나는 이미지 주변의 프레임을보고 싶다. – Hesam

+0

아, convertView.setLayoutParams (새 Gallery.LayoutParams (250, 250))를 추가하여 만들었습니다. \t \t \t \t convertView.setBackgroundResource (mGalleryItemBackground); – Hesam

+0

덕분에 잘 작동합니다. – Hesam

관련 문제