ViewBinding in v3.3.1 version ?
sebastianperdomo opened this issue · 3 comments
Hi, is there any way to use the ViewBinding with the Java && AndroidX v3.3.1 version ?
public class ClientesItem extends AbstractItem<ClientesItem, ClientesItem.ViewHolder> {
public int mCantidadCbtes;
@Override
public int getType() {
return R.id.fastadapter_clientes;
}
@Override
public int getLayoutRes() {
return R.layout.item_clientes_new;
}
@NonNull
@Override
public ViewHolder getViewHolder(View v) {
return new ViewHolder(v);
}
protected static class ViewHolder extends FastAdapter.ViewHolder<ClientesItem> {
private final ItemClientesNewBinding itemBinding;
public ViewHolder(ItemClientesNewBinding itemBinding) {
super(itemBinding.getRoot());
this.itemBinding = itemBinding;
}
@Override
public void bindView(@NonNull ClientesItem item, @NonNull List<Object> payloads) {
if (item.mCantidadCbtes == 0) {
itemBinding.lblCantCbtes.setVisibility(View.GONE);
} else {
itemBinding.lblCantCbtes.setText(String.format("%s", item.mCantidadCbtes));
itemBinding.lblCantCbtes.setVisibility(View.VISIBLE);
}
}
@Override
public void unbindView(@NonNull ClientesItem item) {
itemBinding.lblCantCbtes.setText(null);
}
}
}
this code works fine with findViewById or the butterknife library
with ViewBinding throw error in the getViewHolder function
@Override
public ViewHolder getViewHolder(View v) {
return new ViewHolder(v);
}
Thanks
@sebastianperdomo while it should be possible to achieve (there are a few issues over the time which should give you some helpful pointers, you. may also can look into the item created for kotlin which may give helpful clues).
(this is the abstract item for this https://github.com/mikepenz/FastAdapter/blob/develop/library-extensions-binding/src/main/java/com/mikepenz/fastadapter/binding/AbstractBindingItem.kt)
Regardless it's highly suggested to upgrade to the latest version as we can't give support for old versions. They are provided as is.
what's the error you see when using this sample?
the error is in the line
return new ViewHolder(v);
the "v" variable is the error
tells me that it has to be of the "data type" ItemClientesNewBinding, not View
but if i change the data type with ItemClientesNewBinding, the whole function is in error now
So I suppose you will have to provide the binding class instead, as this one will read in the views and stuff.
As far as I can tell this is not a library issue though, as such I will close the ticket.
Will regardless still try to point you in the right direction if needed