Android : Smooth scroll to position in Android gridview makes work it wrong

on Saturday, September 13, 2014


I have an app which is loading the images from sdcard to gridview on my main screen. I have created ViewHolder so views was intantiating only once. It all worked well until I put smoothScrollToPosition method.


I call smoothScrollToPosition when activity is resuming or creating, so instantly user grid is scrolled to chosen position. The problem is that it loads images that are at the beginning of the grid.


Lets say I have GridView containing 20 grids. Only 2 have images, first and second, the others are empty (has default image set). Now on the activity start I want to scroll smoothly to 12 position. It should be empty, but 12 and 13 grid are containing images from first and second grid. This problem doesn't exist if there are already images to load on this grid.


My adapter is typical :



if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(R.layout.gridview_cell, parent, false);

holder = new ViewHolder();
holder.day = (TextView) convertView.findViewById(R.id.dayDateTextView);
holder.image = (ImageView) convertView.findViewById(R.id.dayImage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}


I will be thankful for any help. Thanks


0 comments:

Post a Comment