1

I'm quickly realizing this is going to be an issue in Android with a lot of boilerplate and as I started refactoring my code I'm now effectively writing my own half-@ssed version of data binding. I don't want to spend more time generalizing it and re-inventing the wheel. I was wondering if there are any good solutions out there as 3rd party libraries that the community uses.

I've found robo-bindings and I really liked their presentation (focus on unit testing their own stuff, robustness, etc) but it seems like they remain quite small and I'm worried about issues with their library and general support/evolution going forward.

Any other libraries people are using?

Thanks.

Creos
  • 2,445
  • 3
  • 27
  • 45
  • You never really hear much about MVVM on Android. Robobinding seems the most mature from my quick look. Xamarin.Android may be the way to go as that world has used MVVM for a long time! – Dori Mar 04 '15 at 11:56
  • You oughta look at AnnotatedAdapter: https://github.com/sockeqwe/AnnotatedAdapter. It automatically binds views in RecyclerView. – IgorGanapolsky Jun 26 '15 at 01:24

1 Answers1

2

Android M will provide powerful library for data binding!

It's available now in dev-preview version.

It looks amazing inside xml and java files:

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@{user.firstName}"
    />

Java bean:

public class User {
   private final String firstName;
   private final String lastName;
   public User(String firstName, String lastName) {
       this.firstName = firstName;
       this.lastName = lastName;
   }
   public String getFirstName() {
       return this.firstName;
   }
   public String getLastName() {
       return this.lastName;
   }
}

Binding:

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);
   User user = new User("Test", "User");
   binding.setUser(user);
}
Salmaan
  • 3,543
  • 8
  • 33
  • 59
  • that's fantastic, thank you, i have to look into this! do you know if there will be compatibility mode where you can use it even for phones that are not on M? – Creos Jun 13 '15 at 13:59
  • Well... I think they must have considered backwards compatibility... I hope it works with previous versions too... – Salmaan Jun 13 '15 at 20:37
  • 2
    it's a support library, so you can use it with all Android platform versions back toAndroid 2.1 (API level 7+) (Y) – Salmaan Jun 13 '15 at 20:38
  • @Salmaan Devs now have to be careful not to mix too much business logic in their layout files. Can you think back to JSP days and their lousy architecture?? – IgorGanapolsky Jun 26 '15 at 01:26
  • Indeed, @IgorGanapolsky some of the very many forms of MVC or any other design that formalizes separation of concerns becomes critical for non-trivial apps... – Creos Jun 30 '15 at 22:54