burakeregar/GenericRecyclerAdapter

How to implement onclick on item?

JobGetabu opened this issue · 1 comments

How to implement onclick on item?

Use greenbot eventbus.
implementation 'org.greenrobot:eventbus:3.0.0'
Then in your view holder bindData()
SingleItemRootLayout rootLayout = view.findViewById(R.id.contact_row); rootLayout.setOnClickListener(v -> EventBus.getDefault().post(Model));

In your activity onCreate() just have
Eventbus.getDefault().register(this)

then create a private method in your activity to handle the onclick event
@Subscribe(threadMode = ThreadMode.MAIN) public fun onRowClicked(pModel: OrderModel) { Toast.makeText(this, "Name: " + pModel.id + " Surname: " + pModel.createdAt, Toast.LENGTH_SHORT).show(); }