Skip to content Skip to sidebar Skip to footer

Listview Items Change Position On Scroll

I have Implemented a ListView which loads news, but news changes position when I scroll the list. this is list public class ListNewsFragment extends SherlockListFragment{ private

Solution 1:

Change your getView() method to this:

Map<Integer, View> views = new HashMap<Integer, View>;

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

    if (views.containsKey(position)) {    
         return views.get(position);
    }

     inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);         
     holder = new ViewHolder();
     View v = inflater.inflate(R.layout.fragment_list_news, null);

     holder.name = (TextView) v.findViewById(R.id.tittle);
     holder.tweet = (TextView) v.findViewById(R.id.news);
     holder.avatar = (ImageView) v.findViewById(R.id.image);

     holder.name.setText(news.get(position).getTitulo());
     holder.tweet.setText(news.get(position).getCopete());
     new ImagefetcherTask(position).execute(holder);

     v.setTag(holder); 
     views.put(position, v);
     return v; 

}

Solution 2:

Call your ImageFetcher and TextView.seText after your else statement so that when the convertView isn't null and has been recycled, you're updating your row:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        holder = new ViewHolder();
        v = inflater.inflate(R.layout.fragment_list_news, null);

        holder.name = (TextView) v.findViewById(R.id.tittle);
        holder.tweet = (TextView) v.findViewById(R.id.news);
        holder.avatar = (ImageView) v.findViewById(R.id.image);

        v.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.name.setText(news.get(position).getTitulo());
    holder.tweet.setText(news.get(position).getCopete());
    new ImagefetcherTask(position).execute(holder);
    return v;
}

Solution 3:

I have fixed this by overriding these two methods in my adapter class.

@OverridepublicintgetViewTypeCount() {
   return getCount();
}

@OverridepublicintgetItemViewType(int position) {
   return position;
}

Solution 4:

Try to do lazy load an image by using this Universal image loader library. and try to catch image.

so as per this answer set the bitmap options as

DisplayImageOptionsoptions=newDisplayImageOptions.Builder()
                        .showImageOnLoading(R.drawable.ic_stub)
                        .showImageForEmptyUri(R.drawable.ic_empty)
                        .showImageOnFail(R.drawable.ic_error)
                        .cacheInMemory(true)
                        .cacheOnDisc(true)
                        .considerExifParams(true)
                        .build();

I am sure this will solve your problem

Post a Comment for "Listview Items Change Position On Scroll"