ListView Changing Items During Scroll

后端 未结 5 410
野性不改
野性不改 2021-01-13 15:05

I am implementing a ListFragment using a custom ArrayAdapter to populate the list. Each row item has an ImageView and three TextViews. Data is being parsed via XML and the i

5条回答
  •  心在旅途
    2021-01-13 15:36

    First of all define in getView() method into convertView=null; and comment else condition in this method and add int type = getItemViewType(position);. Also remove static keyword from each View item like Textview, ImageView in ViewHolder class.

    NOTE: override getViewTypeCount() and getItemViewType() in your adapter.

    if(convertView == null){
     switch (type) {
                case 0:
                      //First view[Row layout]
                break;
                case 1:
                     //Second view[Row layout]
                break;
    
                //another Case here....
    
       convertView.setTag(holder);
    
      //remove else part when used convertView =null;
            /*else {
            holder = (MyViewHolder) row.getTag();
        }*/
    
    } 
    
    @Override
        public int getItemViewType(int position) {
            // TODO Auto-generated method stub
            map = list.get(position); 
            message_type = map.get("message_type");
            if (message_type.equalsIgnoreCase("TEXT")) {
                return 0;
            } else {
                return 1;
            }
    
        }
    
        @Override
        public int getViewTypeCount() {
            // TODO Auto-generated method stub
            if (getCount() != 0)
                return getCount();
            return 2;
        }
    

    Do it now! Done!

提交回复
热议问题