Position of listitem items changes on scrolling

后端 未结 2 1847
余生分开走
余生分开走 2021-01-25 15:48

I have following code in which i am doing JSON parsing and showing results in listview. The problem i am facing is whenever i am scroll the listview my listview contents positio

相关标签:
2条回答
  • 2021-01-25 16:34

    Try to follow viewHolder pattern as below

            ViewHolder holder;
            if(convertView == null) 
            {
                 holder = new ViewHolder();            
                 convertView = mInflater.inflate(R.layout.cat_content, null);
    
                 holder.name =  (ImageView)convertView.findViewById(R.id.name); 
                 convertView.setTag(holder);
            }
            else
            {     
                holder = (ViewHolder) convertView.getTag();     
            } 
    
            item = new HashMap<String, String>();
            item = data.get(position);
            holder.name.setText(item.get(CATEGORY_NAME));
    
            return convertView;
    
    
    
    
    class ViewHolder
    {
         TextView name;
    }
    
    0 讨论(0)
  • 2021-01-25 16:45

    change your getView like this if it help you..

    public View getView(int position, View convertView, ViewGroup parent) {
    
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.cat_content, null);
         }
    
         name = (TextView) convertView.findViewById(R.id.name);
         item = new HashMap<String, String>();
         item = data.get(position);
         name.setText(item.get(CATEGORY_NAME));
    
        return convertView;
    }
    
    0 讨论(0)
提交回复
热议问题