2013-04-03 36 views
0

這是我的代碼,我使用的是用來顯示在GridView控件庫,但顯示所有圖片在這樣我想表明的畫廊在文件夾視圖

Sample Link 1圖像gridview的,但我想顯示畫廊這樣

http://www.google.com.pk/imgres?hl=en&biw=878&bih=598&tbm=isch&tbnid=17fWAXUGZ3USxM:&imgrefurl=http://www.maclife.com/article/howtos/sync_your_android_phone_your_mac?page=0,2&docid=FGf7ur67XeENhM&imgurl=http://www.maclife.com/files/u32/1201_videogallery_480.jpg&w=480&h=854&ei=M9FbUY_aNsrvswburIDABw&zoom=1&iact=hc&vpx=664&vpy=144&dur=1467&hovh=300&hovw=168&tx=123&ty=203&page=1&tbnh=135&tbnw=75&start=0&ndsp=19&ved=1t:429,r:18,s:0,i:133

文件夾視圖,所以當用戶點擊任何文件夾時,它的內容顯示在gridview中我該怎麼做?

這是我的代碼。

 
public class AndroidCustomGalleryActivity extends Activity { 
    private int count; 
    private Bitmap[] thumbnails; 
    private boolean[] thumbnailsselection; 
    private String[] arrPath; 
    private ImageAdapter imageAdapter;

Cursor imagecursor; int image_column_index; Button selectBtn; ProgressDialog myProgressDialog = null; DataBase db; Handler handle = new Handler(){ public void handleMessage(android.os.Message msg) { if (msg.what == 1) { hideProgress(); GridView imagegrid = (GridView) findViewById (R.id.PhoneImageGrid); imageAdapter = new ImageAdapter(); imagegrid.setAdapter(imageAdapter); } else if (msg.what == 3) { hideProgress(); AndroidCustomGalleryActivity.this.finish(); } else if (msg.what == 2) { hideProgress(); } super.handleMessage(msg); }; }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery); showProgress(); new Thread() { public void run() { try { loadFeed(); android.os.Message alertMessage = new android.os.Message(); alertMessage.what = 1; handle.sendMessage(alertMessage); } catch(Exception e) { android.os.Message alertMessage = new android.os.Message(); alertMessage.what = 2; handle.sendMessage(alertMessage); } } }.start(); selectBtn = (Button) findViewById(R.id.selectBtn); selectBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub showProgress(); new Thread() { public void run() { try { SelecedtPhotos(); android.os.Message alertMessage = new android.os.Message(); alertMessage.what = 3; handle.sendMessage(alertMessage); } catch(Exception e) { android.os.Message alertMessage = new android.os.Message(); alertMessage.what = 2; handle.sendMessage(alertMessage); } } }.start(); } }); } public static byte[] getBitmapAsByteArray(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0, outputStream); return outputStream.toByteArray(); } public class ImageAdapter extends BaseAdapter { private LayoutInflater mInflater; public ImageAdapter() { mInflater = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { return count; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.galleryitem, null); holder.imageview = (ImageView) convertView.findViewById (R.id.thumbImage); holder.checkbox = (CheckBox) convertView.findViewById (R.id.itemCheckBox); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.checkbox.setId(position); holder.imageview.setId(position); holder.checkbox.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub CheckBox cb = (CheckBox) v; int id = cb.getId(); if (thumbnailsselection[id]) { cb.setChecked(false); thumbnailsselection[id] = false; } else { cb.setChecked(true); thumbnailsselection[id] = true; } } }); /*holder.imageview.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*"); startActivity(intent); } });*/ holder.imageview.setImageBitmap(thumbnails[position]); holder.checkbox.setChecked(thumbnailsselection[position]); holder.id = position; return convertView; } } class ViewHolder { ImageView imageview; CheckBox checkbox; int id; } public void loadFeed() { final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; final String orderBy = MediaStore.Images.Media._ID; imagecursor = managedQuery (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,null, orderBy); image_column_index = imagecursor.getColumnIndex (MediaStore.Images.Media._ID); this.count = imagecursor.getCount(); this.thumbnails = new Bitmap[this.count]; this.arrPath = new String[this.count]; this.thumbnailsselection = new boolean[this.count]; for (int i = 0; i < this.count; i++) { imagecursor.moveToPosition(i); int id = imagecursor.getInt(image_column_index); int dataColumnIndex = imagecursor.getColumnIndex (MediaStore.Images.Media.DATA); thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail (getApplicationContext().getContentResolver(), id,MediaStore.Images.Thumbnails.MICRO_KIND, null); arrPath[i]= imagecursor.getString(dataColumnIndex); }
+0

我想在gridview之前顯示文件夾中的圖庫,並且還選擇了選定的文件 – nazeer

回答

0

您知道要在網格視圖中顯示的圖像。所以最初得到設計自定義佈局與四個圖像像四個圖像視圖的文件夾。然後加載您的特定文件夾圖像縮略圖。

希望這會幫助你。

+0

我該怎麼做,任何示例? – nazeer

+0

也是我的代碼複製到應用程序文件夾後沒有刪除圖像 – nazeer

相關問題