Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,35 @@ package com.monsterbrain.recyclerviewtableview

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {
class MainActivity : AppCompatActivity(), OnRowClickListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val recyclerViewMovieList = findViewById<RecyclerView>(R.id.recyclerViewMovieList)
recyclerViewMovieList.layoutManager = LinearLayoutManager(this)
recyclerViewMovieList.adapter = TableViewAdapter(movieList)

val adapter = TableViewAdapter(movieList)
adapter.setOnRowClickListener(this)
recyclerViewMovieList.adapter = adapter
}

override fun onRowClick(movie: MovieModel, position: Int) {
// Show a toast message indicating which row was clicked
// In a real app, this would typically start an edit activity
val message = "Clicked on: ${movie.movieName} (Rank ${movie.rank})\n" +
"Year: ${movie.year}, Budget: ${movie.budgetInMillions}M\n" +
"Position: $position"

Toast.makeText(this, message, Toast.LENGTH_LONG).show()

// TODO: In a real implementation, you would start an edit activity here
// Example: startEditActivity(movie, position)
}

// src Wikipedia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView

interface OnRowClickListener {
fun onRowClick(movie: MovieModel, position: Int)
}

class TableViewAdapter(private val movieList: List<MovieModel>) : RecyclerView.Adapter<TableViewAdapter.RowViewHolder>() {

private var onRowClickListener: OnRowClickListener? = null

fun setOnRowClickListener(listener: OnRowClickListener) {
this.onRowClickListener = listener
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RowViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.table_list_item, parent, false)
return RowViewHolder(itemView)
Expand Down Expand Up @@ -36,6 +46,10 @@ class TableViewAdapter(private val movieList: List<MovieModel>) : RecyclerView.A
txtMovieName.text = "Name"
txtYear.text = "Year"
txtCost.text = "Budget (in Millions)"

// Remove click listener for header row
itemView.setOnClickListener(null)
itemView.isClickable = false
}
} else {
val modal = movieList[rowPos - 1]
Expand All @@ -50,6 +64,12 @@ class TableViewAdapter(private val movieList: List<MovieModel>) : RecyclerView.A
txtMovieName.text = modal.movieName
txtYear.text = modal.year.toString()
txtCost.text = modal.budgetInMillions.toString()

// Add click listener for content rows
itemView.setOnClickListener {
onRowClickListener?.onRowClick(modal, rowPos - 1)
}
itemView.isClickable = true
}
}
}
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.