Guest User

Untitled

a guest
Jul 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. //Example of usage
  2. //No need for RxBinding or additonal interfaces to handel views clicks
  3.  
  4. class MainActivity : AppCompatActivity() {
  5. override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
  6. super.onCreate(savedInstanceState, persistentState)
  7. setContentView(R.layout.activity_main)
  8. initializeRecycleView(ArrayList())
  9. }
  10.  
  11. private fun initializeRecycleView(data: List<CourseDo>) {
  12. val adapter = RecycleViewAdapter(data, R.layout.course_row_item, object : ViewHolderBinder<CourseDo> {
  13. private lateinit var tvTitle: TextView
  14. private lateinit var tvDescription: TextView
  15.  
  16. override fun initializeViews(view: View) = with(view) {
  17. tvTitle = findViewById(R.id.tvCourseTitle)
  18. tvTitle.setOnClickListener {
  19. //TODO handle click
  20. }
  21. tvDescription = findViewById(R.id.tvCourseDescription)
  22.  
  23. view.setOnClickListener {
  24. val item: Int = rvAllCourses.getChildLayoutPosition(it)
  25. Toast.makeText(context, "Clicked item is $item ", Toast.LENGTH_LONG).show()
  26. }
  27. }
  28.  
  29. override fun bind(item: CourseDo) {
  30. with(item) {
  31. tvTitle.text = title
  32. tvDescription.text = description
  33.  
  34. }
  35.  
  36. }
  37. })
  38. rvAllCourses.layoutManager = LinearLayoutManager(this)
  39. rvAllCourses.adapter = adapter
  40. }
  41. }
Add Comment
Please, Sign In to add comment