burakeregar / GenericRecyclerAdapter

Easiest way to use RecyclerView. Reduce boilerplate code! You don't need to write adapters for listing pages anymore!
MIT License
52 stars 19 forks source link

How to implement onclick on item? #6

Open JobGetabu opened 5 years ago

Dennis-Mwea commented 5 years ago

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(); }