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 8343641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:07:41+00:00 2026-06-09T06:07:41+00:00

I have a button, and I want it to be enabled only when the

  • 0

I have a button, and I want it to be enabled only when the user has choosen an image
I made this code, but it doesn’t work 🙁

Code updated

Help please ..

the user can get an image by selecting one from the gallery, or capturing one .. if that is related

UPDATE::

these are my camera and gallery code

    btnGallery.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent i = new Intent(
                    Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);
            btnNext.setEnabled(true);
        }
    });

    btnCamera.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(intent, RESULT_LOAD_IMAGE);
            btnNext.setEnabled(true);
        }
    });

and this is the next button code

    btnNext.setEnabled(false);
    btnNext.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {      
            MpClick.start();
            if (btnNext.isEnabled() == false)
            { 
                   Toast.makeText(StartActivity.this,
                            "Please get an image first.", Toast.LENGTH_LONG)
                            .show();
            }
            else
            {
                Intent next = new Intent(StartActivity.this, Option.class);
                startActivity(next);
            }
        }
        });
}

sometimes it takes u to the Option activity and sometimes it doesn’t, and the message never shows ..
I want the message shows when u click on the next button and u didn’t choose an image

but if u choose an image it’ll take u to the Option activity

  • 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-06-09T06:07:43+00:00Added an answer on June 9, 2026 at 6:07 am

    There are a few problems here:

    1. You are closing your if statements with ;… don’t do this.
    2. You are checking setEnabled instead of isEnabled.
    3. You are not surrounding your conditions with ().
    4. You don’t need to check else if, since you’re only checking the opposite of the first conditional. else will do just fine here.

    You should instead be using:

        btnNext.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {               
            if (btnNext.isEnabled() == false)
            { 
                   Toast.makeText(StartActivity.this,
                            "Please get an image first.", Toast.LENGTH_LONG)
                            .show();
            }
            else
            {
                Intent next = new Intent(Main.this, Editing.class);
                startActivity(next);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button that I only want enabled when a textfield is not
I want to only have my navigation bar select button enabled when a row
I want to have a button that has numbers in the range 0 ...
I have a submit button where I want a confirmation pop-up, doing this works
I have a Save Settings button which is of type 'image'. I want it
I have a button that is enabled only when an item is selected in
I have a form, and want to disable/enable its submit button depending on whether
I have if condition and I want to disable or enable my actionLink button.
I have a button I want to use in the beginning and the end
I have a button that I want to make disappear if anything is tapped

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.