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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:24:17+00:00 2026-05-29T20:24:17+00:00

I am trying to use image view as a button. So that when the

  • 0

I am trying to use image view as a button. So that when the user clicks on the image i want a differenot xml file to be displayed as layout.

I have changed as follows..

<ImageView
            android:id="@+id/telugu"
            android:layout_width="130dp"
            android:layout_height="25dp"
            android:layout_x="-34dp"
            android:layout_y="315dp"
            android:clickable="true"
            android:onClick="myClickHandler"

and myClickHandler is..

public void myClickHandler(View view) {
      switch (view.getId()) {
      case R.id.arts:
           setContentView(R.layout.arts);
     case R.id.music:
         setContentView(R.layout.music);

The problem is i am unable to go to the specific layout. It is going to the same layout no matter which image I select.

  • 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-29T20:24:20+00:00Added an answer on May 29, 2026 at 8:24 pm

    Your switch statement is wrong

    switch (view.getId()) {
          case R.id.arts:
               setContentView(R.layout.arts);
         case R.id.music:
             setContentView(R.layout.music);
    }
    

    should be

    switch (view.getId()) {
          case R.id.arts:
               setContentView(R.layout.arts);
               break;
         case R.id.music:
             setContentView(R.layout.music);
             break;
    }
    

    You aren’t putting breaks in your switch which is allowing your switch to drop down to the next statement. This means the setContentView method that you call will always be the bottom one in your switch. Add the “break;”s in there that I showed and you will be good to go

    I’m not sure where people are getting the idea that you can’t call setContentView more than once. This certainly is possible and I’ve just tested it myself to make sure.

    The problem comes with managing data on the screen when simply calling setContentView.
    If you have a layout with 2 buttons on the screen and then switch to one with 3 buttons on the screen you have to somehow differentiate between those layouts in your code. In this case using a whole new activity would be the better option. Less logic code and overall easier to manage. However, I’m sure there are cases where calling setContentView more than once in the same activity is the suitable answer

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

Sidebar

Related Questions

I am trying to use a image button in a grid view to select
I' have a view that contains several textViews an ImageView and a Button .
I'm trying to use an ImageView as a Button , and I want to
I have a simple class that I want to use to show a Dialog
I am trying to use the boost generic image library to convert CYMK images
I trying to use ImageInfo and Jython to get information from a image on
I'm trying to use the following code to make an image fadeOut and, only
I'm trying to use GreaseMonkey to replace the background image of a DIV on
alt text http://www.freeimagehosting.net/image.php?a55fa98f01.jpg Hi I am trying to use a HTML select box with
I am trying to add an image to the UIBarButtonItem which I have to

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.