具有图像组标题名称的Gridview适配器图像

时间:2014-05-16 13:40:43

标签: java android listview gridview adapter

我有一个gridView女巫包含一组有两列的图像,我想要做的是为一组图像添加标题。

现在我可以这样做,但标题的问题是标题只在一列中,第二列总是空的,我怎么能把标题放在两列?

这是我的适配器:

public class MultimediaPhotosAdapter extends BaseAdapter {

private Context mContext;
private List<ImagesDto> imagesDto = new ArrayList<ImagesDto>();
ImagesFlickrDto imagesFlickrDto;
final String formatImage = ImagesNameFormat.FORMAT_IMAGE_DEFAULT.getImagesNameFormat();
ImagesFormatsDto currentImageFormatToDisplay;
GridView gridViewImages;

public MultimediaPhotosAdapter(Context context, GridView gridViewImages) {
    this.gridViewImages = gridViewImages;
    this.mContext = context;
}

@Override
public int getCount() {
    return imagesDto.size();
}

@Override
public Object getItem(int position) {
    return imagesDto.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View itemView = null;
    HolderElementGridView holderElementGridView;
    ImagesDto currentImage = imagesDto.get(position);
    if(convertView == null) {
        holderElementGridView = new HolderElementGridView();
        itemView = View.inflate(mContext,R.layout.item_multimedia_photo,null);

        holderElementGridView.image = (NetworkImageView) itemView.findViewById(R.id.imageView);
        holderElementGridView.title = (TextView) itemView.findViewById(R.id.title);
        itemView.setTag(holderElementGridView); 
    }
    else {
        itemView = convertView;
        holderElementGridView = (HolderElementGridView)itemView.getTag();
    }

    if(imagesDto.get(position).isFirstElementOfCategorie()){
    holderElementGridView.image.setVisibility(View.GONE);
        holderElementGridView.title.setVisibility(View.VISIBLE);
        holderElementGridView.title.setText(currentImage.getTitle());

    } 
    else if(imagesDto.get(position).getUrl()!=null){
        holderElementGridView.image.setVisibility(View.VISIBLE);
        holderElementGridView.title.setVisibility(View.GONE);
        holderElementGridView.image.setImageUrl(StringFormat.getUrlImage(mContext, currentImage.getUrl(), currentImageFormatToDisplay.getSuffix(), currentImageFormatToDisplay.getExtension()),VolleySingleton.getInstance(mContext).getImageLoader());

        holderElementGridView.image.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                DrawerLayoutInterface screenInterface=(DrawerLayoutInterface)mContext;
                if(screenInterface!=null)
                    screenInterface.showDiaporama(imagesFlickrDto,position);

            }
        });
    }
    // column near title is empty
    else{
        holderElementGridView.image.setVisibility(View.VISIBLE);
        holderElementGridView.title.setVisibility(View.GONE);
    }
    return itemView;
}

public void update(ImagesFlickrDto imagesFlickrDto){
    this.imagesFlickrDto = imagesFlickrDto; 
    this.imagesDto = imagesFlickrDto.getListImages();
    AdministrerImagesSA administrerImages = new AdministrerImagesSAImpl();
    currentImageFormatToDisplay = administrerImages.getFormatByProriete(imagesFlickrDto.getImagesFormatsDto(), formatImage);
}

class HolderElementGridView{
    NetworkImageView image;
    TextView title;
}
}

item_multimedia_photo.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:geekui="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<com.netcosports.anderlecht.activity.utils.TypefaceTextView
  android:id="@+id/title"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="@dimen/text_size_item_menu"
  android:visibility="gone"
  android:layout_marginLeft="5dp"
  geekui:customTypeface="fonts/DIN-Regular.otf" />

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginRight="5dp"
    android:layout_marginLeft="5dp"
    android:src="@drawable/ic_launcher" >
</com.android.volley.toolbox.NetworkImageView>

   </LinearLayout>
</LinearLayout>

0 个答案:

没有答案