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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:16:11+00:00 2026-06-17T23:16:11+00:00

where is the best place to put onclick listeners in android activity? I have

  • 0

where is the best place to put onclick listeners in android activity? I have seen two different ways. one way is to put them inside the onCreate method, and another way is to put them below and outside the onCreate method.

I just started a new android app and am confused on where is the best place.

both ways are shown below.

psudo code example one;

onclick method inside of oncreate method

 MainActivity extends Activity{

 onCreate(){

 onClick listeners 

  } // end of onCreate method

 }  // end of MainActivity class

psudo code example two;

putting onclick below and outside oncreate method

 MainActivity extends Activity{

 onCreate(){

 } // end of onCreate method

 onClick listeners

 }  // end of MainActivity class
  • 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-06-17T23:16:13+00:00Added an answer on June 17, 2026 at 11:16 pm

    Both way are correct. How you organize the code is actually for readability’s sake. If you have too many listeners in onCreate(), it’s harder to read the code through afterwards. However, if you just have one and it’s one liner, it’s good to put it in onCreate().

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

Sidebar

Related Questions

Of the two choices, which is the best place to put the variable of
I wanna know where is the best place to put the ini_set() functions, because
I'm wondering what is the best place to put the viewport tag. after <title>
Is there a consensus about the best place to put Python unittests? Should the
Just wondering the best way to replace in place matches on a string. value.replace(bob,
Where is the best place to put sensible data in Symfony2, i.e. PayPal Variables
I am not sure where the best place to put validation (using the Enterprise
I'm trying to figure out the best place to put xdebug's excellent xdebug_time_index() function
This is a rookie question. What's the best place to put @Resource private DataSource
I have written several scripts for my hudson builds. I have place them in

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.