2012-03-30 12 views
1

私はアンドロイドアプリで作業しているカスタムカメラとギャラリービューを持っています。私のカメラは、私が正常に私のギャラリーに表示されている特定のフォルダ内の名前として基本的にタイムスタンプ付きの画像を保存します。それは、古いものから最新のもの、またはアルファベット順のこれらの画像をデフォルトで並べ替えるようですが、反対の順序で表示したいのですが...誰かが正しい方向に向けることができますか?出来ますか?これを試してみて、それが動作するかどうか私に教えてギャラリーの日付で画像を並べ替える方法はありますか?

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; 
    } 

} 

答えて

0

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)); 



    } 



} 

私のカスタムアダプタ:私は...

私のギャラリーの活動を私のBaseAdapterか、私のギャラリー活動の私のOnCreateのを変更できますか

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"); 
関連する問題