3

Quick question on Android development. Is it good practice to access UI elements from code, i.e R.id.example? Or is there something similar to WPF's data binding?

Comments
  • 0
  • 4
    Acessing the UI elements with "findById(R.id.xyzview)" is the way to go. You should do that once in onCreate() (Activity) or in onViewCreated() (Fragment) and store the reference in a global variable.
    There is no such thing as databinding in Android.
  • 3
    There is databinding. I personally haven't used it but have read a few things about it. https://developer.android.com/topic...
  • 2
    @discosama
    I did not know about this. And I have never seen it being used in any project.
    Sounds interesting. I will have a look :)
  • 1
    You should also have a look at ButterKnife.
  • 2
    @tim636373 Once I have learned about it I got used to use databinding. And if you haven't tried it yet, you should give Jake warthon's butter knife a try (@DavidINC you too). Its a view injection library. :)
  • 1
    @arpitbatra thanks, I'll do that.
  • 0
  • 0
    @m4lik thanks for the input!
  • 0
    Or if you use Kotlin, look at the Android Extensions. Big fan, of referencing the views using their ID straight in my Kotlin files. But make sure you have some sort of naming conventions for the views
Add Comment