I'm trying to use Android's Data Binding features with a custom adapter and a ListView. I'm having trouble overriding the custom adapter's getView method:
public class ChecksAdapter extends ArrayAdapter<Check> {
public ChecksAdapter(Context context, ObservableList<Check> checks) {
super(context, R.layout.check, checks);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CheckBinding binding = DataBindingUtil.inflate(
LayoutInflater.from(getContext()),
R.layout.check, parent, false);
binding.setCheck(this.getItem(position));
// Return what?
}
}
So my questions are:
- Where do I get the
Viewelement that I should be returning? Or in other words, how can I bind the object to an inflated/converted view? - How can I reuse
convertViewwhen using data binding? - Is this the correct way to implement this? The guide is not very clear on ListViews
Here's the only reference of ListViews in the guide:
If you are using data binding items inside a ListView or RecyclerView adapter, you may prefer to use:
ListItemBinding binding = ListItemBinding.inflate(layoutInflater, viewGroup, false); //or ListItemBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.list_item, viewGroup, false);