jonny
jonny

Reputation: 797

show image from database where you saved the path of image

Hello i have saved in my databse the path of an image .How can i show the image on the screen?The image path is saved in column "photo" in table "contactTest1" ! Now i can show on my screen only the path of image for each contact like this:

enter image description here

i use this in 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);

this the code i use to get path of image:

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

    }

Upvotes: 0

Views: 379

Answers (1)

barry
barry

Reputation: 4147

You'll have to extend the SimpleCursorAdapter and override getView() which is where, for every item in your list, you can layout the data in the row.

For the image, I think there is a class called BitmapFactory which you can use to create images from urls, paths etc. I haven't used it myself, so can't give an example I'm afraid.

Good luck!

Upvotes: 2

Related Questions