• Post Reply Bookmark Topic Watch Topic
  • New Topic

Button OnClickListener Class

 
siddharth sekhar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello , is it a good practice to separate the OnClickListener class into a separate class  , for example





the code is working fine for now but will this create any bug in the future , just want some good suggestion for developing robust and neat code , Thank you
 
Brian Tkatch
Bartender
Posts: 568
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know what most people do, and its probably just a matter of style. I would just go with what feels right for that particular app.
 
Tim Moores
Saloon Keeper
Posts: 3337
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 on this being a personal choice based on the circumstances. I tend to create a named class if the anonymous class gets larger than 10-15 lines of code, since it gets in the way of readability at that point.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you know, in your xml layout, you can define this as your button attribute


In your java code you can then have a method


This way, you need not do any look up by ID nor explicitly assign any click listener

Recommended reading: https://developer.android.com/reference/android/widget/Button.html
 
siddharth sekhar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!