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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:36:24+00:00 2026-05-20T21:36:24+00:00

I am new to Android and exploring it at the moment. I have two

  • 0

I am new to Android and exploring it at the moment.
I have two Image Buttons which have to load different activities onClick.

ImageButton btn1= (ImageButton)findViewById(R.id.timetable);
btn1.setOnClickListener(btnListener1);

ImageButton btn2= (ImageButton)findViewById(R.id.location);
btn2.setOnClickListener(btnListener2);
private OnClickListener btnListener1 = new OnClickListener()
{
    public void onClick(View view)
    {                        
         Intent myIntent = new Intent(getBaseContext(), HelloWorld1.class);
         startActivity(myIntent);
    }
};

private OnClickListener btnListener2 = new OnClickListener()
{
    public void onClick(View view)
    {                 
        Intent myIntent2 = new Intent(getBaseContext(), HelloWorld2.class);         
        startActivity(myIntent2);
    }
};

//my manifest ……

<activity android:name="myApp" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>        
<activity android:name=".HelloWorld1"></activity>
<activity android:name=".HelloWorld2"></activity>

//and my main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget34"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff"
>

<GridView
    android:id="@+id/widget36"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numColumns="2"
    android:layout_x="110px"

    android:layout_y="32px"
    android:layout_centerInParent="true">
</GridView>
<ImageButton
    android:id="@+id/timetable"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="210px"
    android:layout_y="142px"
    android:background="@drawable/icon2">
</ImageButton>
<ImageButton
    android:id="@+id/location"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="100px"
    android:layout_y="342px"
    android:background="@drawable/icon">
</ImageButton>

This code causes errors, could anyone point where I am going wrong please.
Many thanks in advance.

  • 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-20T21:36:25+00:00Added an answer on May 20, 2026 at 9:36 pm

    Let’s put aside the finish() method since i dont know what the heck it’s doing there 🙂
    Case1: Look careful at your activity xml view file, you might accidentally define your button as Button instead of ImageButton -> Error

    Case2: dont use view.getContext(), instead use getBaseContext() or getApplicationContext()

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

Sidebar

Related Questions

For a new Android project I need buttons which are 'shining' when focused or
I have no idea, which files should be versioned for a new android project
I am completely new to android, and pretty much a Java newb. I have
i'm new at Android world, and i have a doubt, is there any method
When creating a new android project, the build target has two choices: Android 2.2,
I have a new android app I put on the marketplace a few days
Hi i'm new android. i'm working through the samples and have an error when
As a new android programmer I have my obligatory todo app running. It is
hi i am a new android developer. In my app i have created a
So I created a new Android junit test, which runs my ui-automation tests (Robotium,

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.