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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:54:26+00:00 2026-05-27T08:54:26+00:00

Problem: I am trying to capture click event of the ImageButton. I am not

  • 0

Problem: I am trying to capture click event of the ImageButton.
I am not able to capture the clickable event.I have used foll code

Question : Is setOnClickListener the proper way to capture ImageButton or anyother way to capture click event.
Let me know, if i can provide any more thing.

FoodType.java

public class FoodType extends Activity {

    ImageButton btnFoodType1,btnFoodType2;

    public void onCreate(Bundle bundleInstance)
    {
        super.onCreate(bundleInstance);
        setContentView(R.layout.food_type);


        btnFoodType1 = (ImageButton)findViewById(R.id.btnFoodType1);
        btnFoodType2 = (ImageButton)findViewById(R.id.btnFoodType2);

        btnFoodType1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                setContentView(R.layout.veg_category_type);
            }
        });

        btnFoodType2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                setContentView(R.layout.non_veg_category_type);
            }
        });
    }
}

Here goes the XML for the layout used.The property for ImageButton used android:clickable=”true”

*food_type.xml*

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/pizza"
    android:gravity="center"
    android:orientation="horizontal" >


    <ImageButton
        android:id="@+id/btnFoodType1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="255dp"
        android:background="@drawable/veg"
        android:clickable="true"
        android:src="@drawable/ic_launcher" />


    <ImageButton
        android:id="@+id/btnFoodType2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="182dp"
        android:background="@drawable/nonveg"
        android:clickable="true"
        android:src="@drawable/ic_launcher" />

</LinearLayout>
  • 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-27T08:54:27+00:00Added an answer on May 27, 2026 at 8:54 am

    The problem is solved.
    The mistake i had made is:

    Mistake 1: Not entered Activity details in AndroidManifest.xml.

    Mistake 2: Rather calling activity directly, I was calling layout.xml.

    Actually the control was not coming from Activity 1 to Activity 2,Because I have directly called the

    setContentView(R.layout.ui2.xml); 
    

    Mistake 1 is solved by entering the details in AndroidManifest.xml

    <activity android:name="Sample"></activity>
    

    Mistake 2 is solved by change in Activity1.java.Rather calling xml, I have called Activity2.class using Intent.

      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.splash);
          entry_button = (Button) findViewById(R.id.btnEntry);
          entry_button.setOnClickListener(new View.OnClickListener() {
    
              @Override
              public void onClick(View view) {
                  // TODO Auto-generated method stub
                  // Earlier mistake commented
                  // setContentView(R.layout.food_type);
                  Intent splashIntent = new Intent(view.getContext(), FoodType.class);
                  startActivityForResult(splashIntent, 0);
              }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a slight problem, I am trying to capture the input of two
I have a problem here and need your help. I've been trying to capture
I have 2 textboxes that I'm trying to capture the onchange event for. These
I'm trying to capture the mousewheel event on a Silverlight 4 DataGrid. The problem
The following markup is exaggerated to demonstrate the problem. I'm trying to capture the
I have a problem trying to design some generic storage.. Basically I have the
I have a problem trying to edit. I work with Areas for better management
Case : Again trying to capture packets through my NIC, I have developed 2
Here's my problem. I have three controls in a row (they capture people's names).
I have an app where I'm trying to capture voice recordings and video recordings.

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.