2011-12-30 83 views
0

你好,我保存在我的數據庫圖像的路徑。如何在屏幕上顯示圖像?圖像路徑保存在表「 contactTest1「! 現在我可以在我的屏幕上顯示圖像的唯一的路徑,這樣每個聯繫人:從數據庫中顯示圖像,你保存圖像的路徑

enter image description here

我用這個在dbconsole.java:

 private static String[] FROM = { DbConstants.NAME, DbConstants.PHOTO, DbConstants.EMAIL,DbConstants.URL_STRING,DbConstants.ADRESS,DbConstants.PHONE,_ID}; 
    private static int[] TO ={R.id.name,R.id.edittext1}; 

    private void showContacts(Cursor cursor) { 
     //set up data binding 
     SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO); 
     setListAdapter(adapter); 

我用它來獲取代碼圖像路徑:

   Button sButton = (Button) findViewById(R.id.button1); 
    sButton.setOnClickListener(new OnClickListener() { 

      public void onClick(View arg0) { 
       // in onCreate or any event where your want the user to 
       // select a file 
       Intent intent = new Intent(); 
       intent.setType("image/*"); 
       intent.setAction(Intent.ACTION_GET_CONTENT); 
       startActivityForResult(Intent.createChooser(intent, 
         "Select Picture"), SELECT_PICTURE); 
      } 
     }); 




      public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode == RESULT_OK) { 
      if (requestCode == 1) { 
       // currImageURI is the global variable I'm using to hold the content:// URI of the image 
       Uri currImageURI = data.getData(); 
       getRealPathFromURI(currImageURI); 

      } 
     } 
     } 


    public String getRealPathFromURI(Uri currImageURI) { 
     // can post image 
     String [] proj={MediaStore.Images.Media.DATA}; 
     Cursor cursor = managedQuery(currImageURI, 
       proj, // Which columns to return 
       null,  // WHERE clause; which rows to return (all rows) 
       null,  // WHERE clause selection arguments (none) 
       null); // Order-by clause (ascending by name) 
     int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     cursor.moveToFirst(); 


      poza=(EditText)findViewById(R.id.editText1); 
      poza.setText(currImageURI.toString()); 
      return cursor.getString(column_index); 

    } 

回答

2

您必須擴展SimpleCursorAdapter並覆蓋getView(),這是您的列表中的每個項目的位置,您可以佈置該行中的數據。

對於圖像,我認爲有一個名爲BitmapFactory的類,您可以使用它從URL,路徑等創建圖像。我自己並沒有使用它,因此無法舉例恐怕。

祝你好運!

+0

應該說,這就是如果你決定不在數據庫中存儲一個blob。 – barry 2011-12-30 17:42:20

+0

jonny - 你最終做了什麼?你解決了這個問題嗎? – 2013-08-27 19:15:07

相關問題