Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim method in databinding android

Is it possible trim() method is work on two ways data binding, when getting info from XML. If yes how?

android:text='@={contact.contactDetails.name}'
like image 655
Lovekesh Avatar asked Oct 30 '22 23:10

Lovekesh


1 Answers

You can trim it in getter/setter method of you model class.

public class UserModel {
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name.trim();
    }
}

android get it with binding.getUser().getName() , even you can use trim() in getName() both will work same.

like image 104
Ravi Avatar answered Nov 15 '22 07:11

Ravi