Skip to content Skip to sidebar Skip to footer

Position Of Listitem Items Changes On Scrolling

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 position g

Solution 1:

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;




classViewHolder
{
     TextView name;
}

Solution 2:

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;
}

Post a Comment for "Position Of Listitem Items Changes On Scrolling"