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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:39:35+00:00 2026-06-08T22:39:35+00:00

XML <ImageButton android:layout_width=wrap_content android:layout_height=wrap_content android:id=@+id/imageButton1 android:src=@drawable/image1 android:onClick=buttonClick /> JAVA ——————– public void buttonClick(View v)

  • 0
XML     
<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton1"
        android:src="@drawable/image1"
        android:onClick="buttonClick"
    />

JAVA
--------------------
public void buttonClick(View v)
{
    Button aButton = (Button)v;
    aButton.setBackgroundResource(R.drawable.image2);
}

Here’s what I’ve tried so far with no luck…

I want to be able to click the button and change the image to image2, there’s also going to be other images i’ll change it to based off of other variables. I’m just really stuck.. I’ll continue looking at other questions and if I find an answer I’ll post it here.

  • 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-08T22:39:36+00:00Added an answer on June 8, 2026 at 10:39 pm

    Your buttonClick() needs fixing:

    public void buttonClick(View v) 
    {
     ImageButton aButton = (ImageButton)v;
     aButton.setImageResource(R.drawable.image2); 
    } 
    

    the View is an ImageButton, not a Button. The src attribute is updated via setImageResource, not setBackgroundResource.

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

Sidebar

Related Questions

<ImageButton android:id=@+id/previous android:layout_width=wrap_content android:layout_height=wrap_content android:src=@drawable/media_skip_backward android:background=@drawable/transparent></ImageButton> This is what I tried to get a
XML Code: <GridLayout android:id=@+id/grid android:layout_width=fill_parent android:layout_height=fill_parent android:layout_above=@+id/step android:layout_alignParentLeft=true android:layout_alignParentRight=true android:layout_below=@+id/menu > </GridLayout> The above
Please take a look at this XML code: <TableLayout android:id=@+id/tableLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:padding=10dip android:isScrollContainer=true
<?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <LinearLayout android:id=@+id/li android:layout_alignParentTop=true android:layout_width=match_parent android:layout_height=50dip android:orientation=horizontal android:background=@drawable/title_bg>
I have the following xml object representing a ImageButton <?xml version=1.0 encoding=utf-8?> <ImageButton xmlns:android=http://schemas.android.com/apk/res/android
I want to create an Android ImageButton in the xml file with a background
My xml code: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/RelativeLayout1 android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical > <RelativeLayout
<?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/frameLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/background_gradient > <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent android:gravity=center
I got a xml layout file like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout android:id=@+id/tabBar android:layout_width=fill_parent
Hi Ive written a simple android application with two xml pages, one has an

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.