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

  • Home
  • SEARCH
  • 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 6979847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:17+00:00 2026-05-27T17:56:17+00:00

I have an imageview that should be changed on click public class Settings extends

  • 0

I have an imageview that should be changed on click

public class Settings extends Activity implements OnClickListener
{
     private ImageView im1;
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.settings);
         im1 = (ImageView) findViewById( R.id.imageView1 );
         im1.setOnClickListener(this);
     }
     @Override
     public void onClick(View v)
     {
         // TODO Auto-generated method stub
         if (v == im1 )
         {
             Log.d("test", "hey!");
             v.setBackgroundResource(R.drawable.img1);
         }
     }
}

when clicked the method runs and prints out “hey!” but the image won’t change?

EDIT: forgot to mention that imageview contains another image provided by xml layout file

  • 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-27T17:56:17+00:00Added an answer on May 27, 2026 at 5:56 pm

    By convention, you should be using setImageResource(R.drawable.img1); (or setImageDrawable(getResources().getDrawable(R.drawable.img1));) instead of setBackgroundResource(R.drawable.img1);.

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

Sidebar

Related Questions

I have an onClickListener that should call a class that shows and image from
In my view i have ImageView.If i click ,it should open nextview. Please help
I have a FrameLayout that contains several ImageView. On the main activity, I record
So, I have an imageview that should display an arbitrary image, a profile picture
I have a ImageView and draw some things on that view. Now I want
I have used ImageView's before and understand the different scale types that can be
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
I have a Cocoa app I'm writing that has an ImageView with a TextView
I have a custom UIButton in my viewcontroller that should have either the image
I have a custom ListView and an ImageView that I'm trying to use as

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.