Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Example of usage
- //No need for RxBinding or additonal interfaces to handel views clicks
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
- super.onCreate(savedInstanceState, persistentState)
- setContentView(R.layout.activity_main)
- initializeRecycleView(ArrayList())
- }
- private fun initializeRecycleView(data: List<CourseDo>) {
- val adapter = RecycleViewAdapter(data, R.layout.course_row_item, object : ViewHolderBinder<CourseDo> {
- private lateinit var tvTitle: TextView
- private lateinit var tvDescription: TextView
- override fun initializeViews(view: View) = with(view) {
- tvTitle = findViewById(R.id.tvCourseTitle)
- tvTitle.setOnClickListener {
- //TODO handle click
- }
- tvDescription = findViewById(R.id.tvCourseDescription)
- view.setOnClickListener {
- val item: Int = rvAllCourses.getChildLayoutPosition(it)
- Toast.makeText(context, "Clicked item is $item ", Toast.LENGTH_LONG).show()
- }
- }
- override fun bind(item: CourseDo) {
- with(item) {
- tvTitle.text = title
- tvDescription.text = description
- }
- }
- })
- rvAllCourses.layoutManager = LinearLayoutManager(this)
- rvAllCourses.adapter = adapter
- }
- }
Add Comment
Please, Sign In to add comment