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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:15:22+00:00 2026-05-26T11:15:22+00:00

ImageButton event listener is not working. Here’s my code (updated): XML: <ScrollView …> <LinearLayout

  • 0

ImageButton event listener is not working.

Here’s my code (updated):

XML:

<ScrollView ...>
    <LinearLayout
       android:orientation="vertical"
       ...
       >
       <HorizontalScrollView
          ...
          >
          <LinearLayout 
         android:orientation="horizontal"
     ...
         >
             <ImageButton
                 android:id="@+id/img_btn1"
     />
          </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
</ScrollView>

Java code:

public class Main extends Activity{
    ImageButton imgBtn1;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imgBtn1 = (ImageButton) findViewById(R.id.img_btn1);
        imgBtn1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.w("onClick", "ImageButton Clicked");
            }
        });
    }
}

This code is not working. Thanks for any help.

  • 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-26T11:15:23+00:00Added an answer on May 26, 2026 at 11:15 am

    This is working fine on mine side:

    setContentView(R.layout.vhscroll);

    ImageButton imageButton = (ImageButton)findViewById(R.id.imagebutton1);

        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(VHScrollViewActivity.this, "You clicked image button", Toast.LENGTH_LONG).show();
            }
        });
    

    and xml code is:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ScrollView  android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content">
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
                <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
                        <ImageButton android:id="@+id/imagebutton1" android:layout_width="100dip" android:layout_height="100dip" android:src="@drawable/sample_0" android:scaleType="fitXY"/>
    </.......>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which creates an ImageButton and plays a sound when
I have an Android activity with an ImageButton. I would like to execute some
I have code, where i add ImageButton to table programaticly and I need to
I am getting an EVENT undefined rror in the ASP.NET C# code below. I
Trying to pass some values into an imagebutton click event, something like this: <asp:ImageButton
I have ImageButton in a MasterPage. I want the OnClick event to fire and
Hello I have one ImageButton with single image. I have added onclick event and
ASP.NET says that the following ImageButton server tag is not well formed: <asp:TableCell VerticalAlign=Top>
Code first: public class ExtendedGridView : GridView { private ImageButton m_btnPrint; public ImageButton PrintButton
My TextView does not support the MotionEvent.Action_UP. I only get 0 on event.getAction. But

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.