• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button OnClickListener Class

 
siddharth sekhar
Ranch Hand
Posts: 31
  • 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: 567
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
Bartender
Posts: 3137
50
  • 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
Saloon Keeper
Posts: 11342
16
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: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic