在android的gridview末尾添加一个额外的布局

时间:2017-05-04 06:12:30

标签: android gridview arraylist baseadapter layout-inflater

我使用基础适配器创建了一个gridview。现在屏幕将如下所示

Current Image

我必须添加一个新的布局作为最后一项,以添加更多如下图像

New design

有没有办法将新布局作为最后一项进行充气并执行不同的操作。我的适配器类如下所示

public class LibraryGridZipAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<MagazineHeaderModel> mHeader;
public LibraryGridZipAdapter(Context context, ArrayList<MagazineHeaderModel> header)
{
    mContext    =   context;
    mHeader     =   header;
}
@Override
public int getCount() {
    return mHeader.size();
}
@Override
public MagazineHeader getItem(int position) {

    return mHeader.get(position).getMagazine_header();
}
@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    final MagazineHeader header             =   getItem(position);
    final HeaderDetail headerDetail     =   header.getMagazine_details();
    if(convertView==null)
    {
        holder                  =   new ViewHolder();
        LayoutInflater inflater =   (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView             =   inflater.inflate(R.layout.layout_libraryitem_landscape,null);
        holder.coverImage       =   (ImageView) convertView.findViewById(R.id.coverimage_library);
        holder.viewButton       =   (Button)    convertView.findViewById(R.id.view_library);
        holder.title            =   (TextView)  convertView.findViewById(R.id.title_library);
        holder.issue            =   (TextView)  convertView.findViewById(R.id.issue_library);
        holder.size             =   (TextView)  convertView.findViewById(R.id.size_library);
        holder.comment          =   (TextView)  convertView.findViewById(R.id.comment_library);
        convertView.setTag(holder);
    }
    else
    {
        holder                  =   (ViewHolder) convertView.getTag();
    }
    String coverPath    =   header.getMag_id()+"/titleimage.png";
    holder.coverImage.setImageBitmap(Functions.getBitmap(Finals.EXTRACT_PATH + coverPath));
    holder.title.setText(header.getName());
    int size=Integer.parseInt(headerDetail.getMagazine_size());
    int sizee=size/1024;
    int sizeee=sizee/1024;
    String siz=String.valueOf(sizeee);
    holder.issue.setText(siz+ "MB");
    holder.viewButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(mContext,MagazineActivity.class);
            intent.putExtra(Finals.INTENT_TAGS.PAGE_ORIENTATION, header.getMag_orientation());
            intent.putExtra(Finals.INTENT_TAGS.MAG_ID, header.getMag_id());
            intent.putExtra(Finals.INTENT_TAGS.PAGE_WIDTH,headerDetail.getMagazine_page_width());
            intent.putExtra(Finals.INTENT_TAGS.PAGE_HEIGHT,headerDetail.getMagazine_page_height());
            mContext.startActivity(intent);
        }
    });
    return convertView;
}
private static class ViewHolder
{
    ImageView   coverImage;
    Button      viewButton;
    TextView    title;
    TextView    issue;
    TextView    size;
    TextView    comment;
}
}

0 个答案:

没有答案