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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:26:02+00:00 2026-05-28T16:26:02+00:00

I am semi-new to android development. I am getting ready to design a project

  • 0

I am semi-new to android development. I am getting ready to design a project that has a button that has 2 different methods when clicked (effectively a toggle). I know I can do this by implementing OnClickListener myself, but I was wondering if there was a way to make 2 different buttons in the layout xml and then conditionally show one or the other appropriately. Also if this is possible, is it generally a good practice, or is there a better way to have a button perform two different methods? Is it easier overall to just go ahead and implement OnClickListener?

Thanks

(I currently don’t have any code to show at the moment, but if my question is vague I’ll be happy to elaborate more if necessary)

  • 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-28T16:26:04+00:00Added an answer on May 28, 2026 at 4:26 pm

    I’ve been thinking about it and if the only difference between the buttons is what they do when clicked, you should use only one button and either:

    1. Use an if/else in the onClick() method or click listener to control the behavior, OR
    2. Use button.setOnClickListener() to change the listener when you want to change the behavior

    However if the buttons are significantly different (e.g. different location …etc), use my other answer.

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

Sidebar

Related Questions

Possible Duplicate: Difference between OnClick() event and OnClickListener? I'm semi-new to Android development and
This is getting Frustrating ... I am semi-new to web services, and I dont
I am semi-new to ASP.NET MVC. I am building an app that is used
I have a semi-large web application that we run locally and I need to
Good evening. I'm developing an android application that uses Facebook SDK. I've no problem
I'm semi-new to writing ASP.Net applications using master pages and I've run into an
Sorry for the semi-generic title, but I'm still pretty new at rails and couldn't
Proficient with SQL but new to MDX, I am having trouble getting my head
I need a Class which has an semi-automatic 'to_s' method (to generate XML in
I've a semi complex LINQ query that is running very slow. I do not

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.