Android - Different items in GridView not showing up

我只是一个虾纸丫 提交于 2019-11-29 15:01:58

I post full getView method from my other answer. Simple you check the position first. If it's the last item (load more button) return layout immediately.

private final Media special = new Media("-1", "", "", "", ""); 


    public MediaGridAdapter(Context context, int imageID, ArrayList<Media> array, int type, boolean isGetMore) {

        list = array;
        mediaType = type;
        this.context = context;

            if(list != null) {
                list.add(special);
            }


    }       



     @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                RelativeLayout item;
                ViewHolder  holder;
//this part check it's the last item. -1 is my special item id in contructor.
                if(list.get(position).getId().equals("-1")) {

                        item = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.item_special_more, null);
                        item.setTag(MORE_BUTTON);
                    return item;
                }
//

                if(convertView == null || convertView.getTag().toString().equals(MORE_BUTTON)) {

                    Context context = parent.getContext();
                    item = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.item_with_icon_vertical, null);
                    holder = new ViewHolder();
                    holder.thumbnail = (ImageView) item.findViewById(R.id.iv_icon_media);

                    item.setTag(holder);

                } else {

                    item = (RelativeLayout) convertView;
                    holder = (ViewHolder) item.getTag();
                }
            }
// set data.
    holder.thumbnail.setBitmap(...) 

    return item;
Jim

Maybe you can try delete row==null and holder = (ViewHolder)row.getTag(); it's because of recycle issue,you can have a try first.But it will affect efficiency. Another thing i want to say,how do position==thumbUrls.size();? Maybe it's position==thumbUrls.size()-1;.Ok,that's my view,i help it work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!