Please tell me how I can do smooth scrolling. When I try to scroll down it takes a lot of time to load videos thumbnails. Please check my code and give me a easy solution. Many thanks.
I have tried a lot of ways but not working. Don't know how to deal with this issue. I hope experts will help me to complete my project.
public class VideoAdapter extends BaseAdapter {
private Context vContext;
public VideoAdapter(Context c) {
vContext = c;
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
ViewHolder holder;
String id = null;
convertView = null;
if (convertView == null) {
try {
convertView = LayoutInflater.from(vContext).inflate(
R.layout.itemlist, parent, false);
}
catch (Exception e)
{
Toast.makeText(getContext(),"Permission Granted" + e, Toast.LENGTH_SHORT).show();
}
holder = new ViewHolder();
try {
holder.txtTitle = (TextView) convertView
.findViewById(R.id.txtTitle);
holder.txtSize = (TextView) convertView
.findViewById(R.id.txtSize);
holder.thumbImage = (ImageView) convertView
.findViewById(R.id.imgIcon);
}
catch (Exception e)
{
Toast.makeText(getContext(),"Permission Granted" + e, Toast.LENGTH_SHORT).show();
}
try {
video_column_index = songCursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
songCursor.moveToPosition(position);
id = songCursor.getString(video_column_index);
video_column_index = songCursor
.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
songCursor.moveToPosition(position);
} catch (Exception e)
{
Toast.makeText(getContext(),"Permission Granted" + e, Toast.LENGTH_SHORT).show();
}
// id += " Size(KB):" +
// videocursor.getString(video_column_index);
holder.txtTitle.setText(id);
holder.txtSize.setText(" Size(KB):"
+ songCursor.getString(video_column_index));
try {
String[] proj = {MediaStore.Video.Media._ID,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.DATA};
@SuppressWarnings("deprecation")
Cursor cursor = getActivity().getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj,
MediaStore.Video.Media.DISPLAY_NAME + "=?",
new String[]{id}, null);
cursor.moveToFirst();
}
catch (Exception e)
{
Toast.makeText(getContext(),"nO Permission Granted" + e, Toast.LENGTH_SHORT).show();
}
long ids = songCursor.getLong(songCursor
.getColumnIndex(MediaStore.Video.Media._ID));
ContentResolver crThumb = getActivity().getContentResolver();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, ids, MediaStore.Video.Thumbnails.MICRO_KIND, options);
/// if (holder.thumbImage !=null) {
holder.thumbImage.setImageBitmap(curThumb);
// }
// else {
// Drawable a = getContext().getResources().getDrawable(R.drawable.index);
/// holder.thumbImage.setImageDrawable(a);
// }
curThumb = null;
}
return convertView;
}
}
static class ViewHolder {
TextView txtTitle;
TextView txtSize;
ImageView thumbImage;
}