1
내 안드로이드 애플 리케이션에서 작동하는 사용자 정의 카메라 및 갤러리보기가 있습니다. 내 카메라는 본질적으로 시간 스탬프가있는 그림을 내 갤러리에 성공적으로 표시되는 특정 폴더의 이름으로 저장합니다. 가장 오래된 것부터 가장 최신의 것 또는 알파벳순으로이 이미지를 기본적으로 정렬하는 것 같습니다.하지만 반대 순서로 표시하고 싶습니다. 누군가 올바른 방향으로 나를 가리킬 수 있습니까? 그것은 가능한가? 난 내 BaseAdapter 또는 내 갤러리 활동 내에서 OnCreate을 ... 변경합니까 갤러리의 날짜순으로 이미지를 정렬 할 수있는 방법이 있나요? android
내 갤러리 활동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;
}
}