gpt4 book ai didi

android - 有没有办法在画廊android中按日期对图像进行排序

转载 作者:行者123 更新时间:2023-11-29 13:59:55 28 4
gpt4 key购买 nike

我的 Android 应用程序中有一个可用的自定义相机和画廊 View 。我的相机将带有时间戳的图片基本上作为它们的名称保存在我已成功显示在我的画廊中的特定文件夹中。似乎它默认将这些图像从最旧到最新或按字母顺序排序,不确定..但我希望它们以相反的顺序显示..有人可以指出我正确的方向吗?是否可以?我应该更改我的 BaseAdapter 还是我的图库 Activity 的 oncreate...

我的画廊 Activity :

public class GalleryView extends Activity{

ImageView imageView;
Cursor cursor;
private int columnIndex;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
Gallery ga = (Gallery)findViewById(R.id.Gallery01);
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Media._ID};
// Create the cursor pointing to the SDCard
cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
MediaStore.Images.Media.DATA + " like ? ",
new String[] {"%LC/images%"},
null);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);

ga.setAdapter(new GallImageAdapter(this,cursor,columnIndex));



}



}

我的自定义适配器:

public class GallImageAdapter extends BaseAdapter {
public Cursor cursor;
private int columnIndex;
private Context context;
int imageBackground;

public GallImageAdapter(Context ctx, Cursor cur, int cIn) {
context = ctx;
columnIndex = cIn;
cursor = cur;
}

@Override
public int getCount() {

return cursor.getCount();
}

@Override
public Object getItem(int position) {

return position;
}

@Override
public long getItemId(int position) {

return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView ==null){
v = LayoutInflater.from(context).inflate(R.layout.galitem, parent, false);
}else{
v = convertView;
}
ImageView photo = (ImageView) v.findViewById(R.id.imageView);
ImageView border = (ImageView) v.findViewById(R.id.borderView);
ImageView d = (ImageView) v.findViewById(R.id.delView);

// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// obtain the image URI
Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
String url = uri.toString();
// Set the content of the image based on the image URI
int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
photo.setImageBitmap(b);

photo.setScaleType(ImageView.ScaleType.FIT_CENTER);

return v;
}

}

最佳答案

最后一个参数用于描述感兴趣的 URI 的顺序。

尝试这种方法来按降序对图像进行排序

final String orderBy = MediaStore.Images.Media._ID;

cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
MediaStore.Images.Media.DATA + " like ? ",
new String[] {"%LC/images%"},
orderBy + " DESC");

关于android - 有没有办法在画廊android中按日期对图像进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9935753/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com