2012-12-07 95 views
1

我在手機內保存了一些圖像並將圖像路徑插入到數據庫中。 我想在數據庫中使用圖像路徑並在gridview中顯示出來。 現在我可以創建一個GridView來展示圖庫應用程序中的圖像。但我真的不知道如何根據數據庫路徑顯示圖像。如果可能的話,誰能在這個問題上啓發我?任何評論將不勝感激。根據數據庫中的圖像路徑在gridview中顯示圖像

下面的代碼我用來在圖庫中顯示圖像。

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.phone_tab); 

    final String[] columns = { MediaColumns.DATA, BaseColumns._ID }; 
    final String orderBy = BaseColumns._ID; 
    Cursor imagecursor = managedQuery(
      MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, 
      null, orderBy); 
    int image_column_index = imagecursor.getColumnIndex(BaseColumns._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(MediaColumns.DATA); 
     thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
       getApplicationContext().getContentResolver(), id, 
       MediaStore.Images.Thumbnails.MICRO_KIND, null); 
     arrPath[i]= imagecursor.getString(dataColumnIndex); 
    } 
    GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid); 
    imageAdapter = new ImageAdapter(); 
    imagegrid.setAdapter(imageAdapter); 
    imagecursor.close(); 

    final Button selectBtn = (Button) findViewById(R.id.select_btn); 
    selectBtn.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      final int len = thumbnailsselection.length; 
      int cnt = 0; 
      String selectImages = ""; 
      for (int i =0; i<len; i++) 
      { 
       if (thumbnailsselection[i]){ 
        cnt++; 
        selectImages = selectImages + arrPath[i] + "|"; 
       } 
      } 
      if (cnt == 0){ 
       Toast.makeText(getApplicationContext(), 
         "Please select at least one image", 
         Toast.LENGTH_LONG).show(); 
      } else { 
       Toast.makeText(getApplicationContext(), 
         "You've selected Total " + cnt + " image(s).", 
         Toast.LENGTH_LONG).show(); 
       Log.d("SelectedImages", selectImages); 

       Intent input = new Intent(v.getContext(), InputScreen.class); 
       input.putExtra("selectImages", selectImages+""); 
       StringBuffer urlString = new StringBuffer(); 
       replaceContentView("InputScreen", input); 

      } 


     } 



    }); 



} 

Values [2] return as /mnt/sdcard/ImageFolder/Image1.jpg。

String values[] = helper.get_user_image(useremail); 
    String filepath = values[2]; 
+0

對於尼斯問題+1。 –

回答

相關問題