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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:07:18+00:00 2026-06-13T16:07:18+00:00

i am trying to change the image in a imageview, but when i set

  • 0

i am trying to change the image in a imageview, but when i set the variable in oncreate it gives me a yellow line making it so i cannot change my image.

in this app i am checking the Internet connection. basically, if the Internet connection is available i want to show a certain image; if not i want to show a image for that.

heres my code:

  @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    ImageView imagev = (ImageView) findViewById(R.id.imageView1);

    Button btnStatus = (Button) findViewById(R.id.btn_check);

    // creating connection detector class instance
    cd = new ConnectionDetector(getApplicationContext());

    /**
     * Check Internet status button click event
     * */
    btnStatus.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // get Internet status
            isInternetPresent = cd.isConnectingToInternet();

            // check for Internet status
            if (isInternetPresent) {
                // Internet Connection is Present
                // make HTTP requests
                showAlertDialog(AndroidDetectInternetConnectionActivity.this, "Internet Connection",
                        "You have internet connection", true);
                imagev.setImageDrawable(getResources().getDrawable(R.drawable.withinternet));

            } else {
                // Internet connection is not present
                // Ask user to connect to Internet
                showAlertDialog(AndroidDetectInternetConnectionActivity.this, "No Internet Connection",
                        "You don't have internet connection.", false);
                imagev.setImageDrawable(getResources().getDrawable(R.drawable.nointernet));
            }
        }

    });

}
  • 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-13T16:07:19+00:00Added an answer on June 13, 2026 at 4:07 pm

    Declare the image view as a class variable i.e., imageV should be declared before onCreate(as a class variable) rather than inside it. It will solve your problem..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop a spinner that can change the image of ImageView
I have an image view and I am trying to change image of imageview
I have activity with android:configChanges=orientation|keyboardHidden I am trying to change image in ImageView when
I am trying to progamatically change the size of my imageView image. I am
I am trying to change an imageview to a new image based on a
I am trying to change desktop image using below code: NSError *anError = nil;
Im working in WPF and I am trying to change the image of a
I am trying to change the background image of a link when it get
I'm trying to make an image change its rotation between 2 position in an
I changed image of cursor. I am trying to change size of cursor image

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.