Pravin
Pravin

Reputation: 1362

Get camera image Inside Iistview

I have custom Listview. Inside it has one Button and ImageView.

on Button click Camera will open.(Camera Intent fired).

I want that captured Image (you also call as Bitmap) onto ImageView which is also a ListItem.

that means when i capture image and press Done button of camera then my imageview have to set that image.

How can i do this?

Upvotes: 0

Views: 108

Answers (2)

toto
toto

Reputation: 1188

 private static int FILE_SELECT_CODE_1 = 0;
    function intentCamera(){
         Intent i = new Intent(
                        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
         startActivityForResult(i, FILE_SELECT_CODE_1);


  }

private String getLastImagePath() {
        final String[] imageColumns = { MediaStore.Images.Media._ID,
                MediaStore.Images.Media.DATA };
        final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
        Cursor imageCursor = managedQuery(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
                null, null, imageOrderBy);
        if (imageCursor.moveToFirst()) {
            //int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
            String fullPath = imageCursor.getString(imageCursor
                    .getColumnIndex(MediaStore.Images.Media.DATA));
            // Log.d(TAG, "getLastImageId::id " + id);
            // Log.d(TAG, "getLastImageId::path " + fullPath);
            imageCursor.close();
            return fullPath;
        } else {
            return "";
        }
    }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == FILE_SELECT_CODE_1 && resultCode == RESULT_OK){
         String lastImagePath = getLastImagePath();
         File fileImage = new File(lastImagePath);
         Uri u = Uri.fromFile(fileImage);
         //now you can set the image example:
         ImageView img = new ImageView(this);
         img.setImageURI(u);




    }
}

Upvotes: 0

Bhavdip Sagar
Bhavdip Sagar

Reputation: 1971

Follow the below steps,

  1. start activity for result of camera intent from your activity.
  2. after capturing picture control callback to onActivityResult of you activity.
  3. handle path of image.
  4. set that path to your image by setting property in your listview item position.

Upvotes: 1

Related Questions