Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1087305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:55:15+00:00 2026-05-16T22:55:15+00:00

Hi I am trying to create a Custom View that takes as well as

  • 0

Hi I am trying to create a Custom View that takes as well as deletes a picture and looks like the following:

alt text

Following operations a view can perform:

  • Take a picture (by clicking on the No Image Available sign) — works
  • Delete a picture (by clicking on the red cross) — works
  • Preview a picture

How do I create a listener to find out when the image has been taken by the camera? The location of the image that needs to be taken is known before.

public class artooPicture extends RelativeLayout {

    ImageView preview, delete;
    String value = Environment.getExternalStorageDirectory() + "/99006796"
            + "_" + ".jpg", suffix;
    boolean clicked = false;

    public artooPicture(Context context) {
        this(context, null);

    }

    public artooPicture(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    }

    public artooPicture(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        ((Activity) getContext()).getLayoutInflater().inflate(R.layout.picture,
                this, true);

        delete = (ImageView) findViewById(R.id.scan_delete);
        preview = (ImageView) findViewById(R.id.scan_preview);

        File f = new File(value);
        if (f.exists()) {
            clicked = true;
            preview.setImageDrawable(BitmapDrawable.createFromPath(value));

        } else {

        }

        delete.setOnClickListener(deleteListener);
        preview.setOnClickListener(previewListener);
    }

    View.OnClickListener deleteListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if(clicked){
                File f = new File(value);
                f.delete();
                preview.setImageResource(R.drawable.no_image);
            }

            clicked = false;
        }
    };

    View.OnClickListener previewListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(value)));
            getContext().startActivity(i);

        }
    };

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:55:16+00:00Added an answer on May 16, 2026 at 10:55 pm

    Solved using Threads. Does anyone have a better solution?

    View.OnClickListener previewListener = new OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                if (!clicked) {
    
                    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri
                            .fromFile(new File(value)));
                    getContext().startActivity(i);
    
                    Thread t = new Thread(new Runnable() {
    
                        @Override
                        public void run() {
                            File f;
                            do {
                                f = new File(value);
                            } while (!f.exists());
                            if (f.exists()) {
                                preview.setImageDrawable(BitmapDrawable
                                        .createFromPath(value));
                                clicked = true;
                            }
                        }
                    });
                    t.run();
    
                } else {
                    Dialog d = new Dialog(getContext());
                    ImageView iv = new ImageView(getContext());
                    iv.setImageDrawable(BitmapDrawable.createFromPath(value));              
                    d.setContentView(iv);
                    d.setCancelable(true);
                    d.show();
                }
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a generic, reusable view, that looks like a lined notepad.
I am trying to create a custom popup view that can be called from
I'm trying to create a CGRect inside of a custom view (rectView) that will
I'm trying to create a custom UIButton that should look like a UIButtonTypeRoundedRect. In
I am trying to create a custom View that would replace a certain layout
I'm trying to create a custom table view cell that has a button on
I'm trying to create custom view that draws image downloaded from Url. The code
I'm trying to create a custom view (one that is not 100% listview, for
I'm trying to create a custom view GhostSurfaceCameraView that extends SurfaceView . Here's my
I'm trying to create a custom view for my UITableView footerView that has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.