我想在GridView中显示存储在SD卡中的所有视频。我跟着this tutorial并根据我的需要进行了更改。以下是我getview()
类
CustomAdapter
的代码
public View getView(int position, View convertView, ViewGroup parent)
{
View listItemRow;
listItemRow = LayoutInflater.from(vContext).inflate(R.layout.sd_card_list_item, parent, false);
TextView txtTitle = (TextView)listItemRow.findViewById(R.id.txtTitle);
ImageView thumbImage = (ImageView)listItemRow.findViewById(R.id.videocapture);
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videoCursor.moveToPosition(position);
txtTitle.setText(videoCursor.getString(videoColumnIndex));
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
videoCursor.moveToPosition(position);
int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
Cursor videoThumbnailCursor = getContentResolver().query(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));
}
thumbImage.setImageURI(Uri.parse(thumbPath));
thumbImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(VideoStoredInSDCardActivity.this,"Video Clicked",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(VideoStoredInSDCardActivity.this,SampleVideoActivity.class);
startActivity(intent);
}
});
return listItemRow;
}
我面临的问题是我的所有视频都获得了相同的缩略图(第一个视频缩略图)。
以上代码有什么问题?
另外,如何在onClickListener
内点击用户点击的视频文件的路径?
提前致谢!
答案 0 :(得分:0)
你总是通过这个视频获得第一个位置的路径.ThumbnailCursor.moveToFirst()
您需要根据位置
在getView方法中保持位置