Simple generic adapter for RecyclerView to show data using DataBinding.
Initialize adapter :
RecyclerAdapter adapter = new RecyclerAdapter<>(this, arraylist, <layout id>, new RecyclerCallback<ItemBindingClassName, ModelClass>() {
@Override
public void bindData(ItemBindingClassName binder, ModelClass model) {
binder.setUser(model);
}
});
use it in acitivity :
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding activityMainBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
RecyclerAdapter adapter = new RecyclerAdapter<>(this, arraylist, <layout id>, new RecyclerCallback<ItemBindingClassName, ModelClass>() {
@Override
public void bindData(ItemBindingClassName binder, ModelClass model) {
binder.setUser(model);
}
});
activityMainBinding.rv.setAdapter(adapter);
}
}