Android - Different items in GridView not showing up

后端 未结 2 875
栀梦
栀梦 2020-12-21 09:13

I am working on app which has a GridView of images but the last item in GridView is a button that loads more item into Grid. But i am facing a strange issue and that is Butt

相关标签:
2条回答
  • 2020-12-21 10:00

    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;
    
    0 讨论(0)
  • 2020-12-21 10:13

    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.

    0 讨论(0)
提交回复
热议问题