本文介绍了来自Mediastore的Android列表中的排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要Android上的视频库,按最新的排序.在下面的代码中,排序是最旧的视频在前,最新的视频在后.因此,在获取新录制的视频之前,我需要滚动整个列表.
I need a video gallery on Android sorted by the newest. With the code below, the sorting is with oldest videos on top and newest videos on last. So I need to scroll the entire list before getting the new recorded videos.
有什么办法解决这个问题吗?
Any ideas to solve this ?
private void init_phone_video_grid() {
System.gc();
String[] proj = { MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE };
videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
count = videocursor.getCount();
videolist = (ListView) findViewById(R.id.PhoneVideoList);
videolist.setAdapter(new VideoAdapter(getApplicationContext()));
videolist.setOnItemClickListener(videogridlistener);
}
private OnItemClickListener videogridlistener = new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
System.gc();
video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videocursor.moveToPosition(position);
String filename = videocursor.getString(video_column_index);
String videoinfo[] = new String[2];
int videoId = videocursor.getInt(videocursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
Cursor videoThumbnailCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID+ "=" + videoId, null, null);
if (videoThumbnailCursor.moveToFirst()) {
thumbPath = videoThumbnailCursor.getString(videoThumbnailCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
Log.d("ThumbPath: ",thumbPath);
}
videoinfo[0] = filename;
videoinfo[1] = thumbPath;
Intent intent = new Intent(StoredVideo.this, VideoCompress.class);
intent.putExtra(EXTRA_MESSAGE, videoinfo);
StoredVideo.this.startActivity(intent);
}
};
推荐答案
解决了:
String orderBy = android.provider.MediaStore.Video.Media.DATE_TAKEN;
videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, orderBy + " DESC");
这篇关于来自Mediastore的Android列表中的排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!