I have a Button that has an Icon and a text.
This is achieved with this code:
<Button
...
android:drawableLeft="@drawable/ghana"
android:drawableStart="@drawable/ghana"
android:text="@string/hint_ghana"
/>
Databinding works with the text but not with the icon when I do this:
<Button
...
android:drawableLeft="@{countryOfResidence.thumbnail}"
android:drawableStart="@{countryOfResidence.thumbnail}"
android:text="@{countryOfResidence.countryName}"
/>
This is the result:
I have looked for a solution to this but can't find any as most are focused on loading an image into and ImageView.
My Model class looks like this:
public class CountryOfResidence {
private String countryName;
private int thumbnail;
public CountryOfResidence(String countryName, int thumbnail) {
this.setCountryName(countryName);
this.setThumbnail(thumbnail);
}
....
In the onCreate() method of the calling Activity, am doing this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivitySignUpBinding signUpBinding = DataBindingUtil.setContentView(this, R.layout.activity_sign_up);
MyHandler myHandler = new MyHandler();
signUpBinding.setMyHandler(myHandler);
mViewFlipper = (ViewFlipper) findViewById(R.id.signUpViewFlipper);
countryOfResidenceList = new ArrayList<>();
countryOfResidenceList.add(new CountryOfResidence("Nigeria", R.drawable.nigeria));
countryOfResidenceList.add(new CountryOfResidence("Ghana", R.drawable.ghana));
countryOfResidenceList.add(new CountryOfResidence("Kenya", R.drawable.kenya));
signUpBinding.setCountryOfResidence(countryOfResidenceList.get(1));
Finally, the data tag in my layout looks like this
<data>
...
<variable
name="countryOfResidence"
type="orem_tech.com.teylur.model.CountryOfResidence"/>
</data>
Any advice?

