Когда я нажимаю на элемент (название курса) в повторном просмотре, я перехожу на новый вид деятельности. Тем не менее, мне нужно только 2 курса, чтобы работать на данный момент. Для остальных элементов в обзоре я не хочу добавлять целевую активность. Вместо этого я просто хочу добавить всплывающее сообщение, например, «Эта функция еще не доступна». Как мне это сделать?
Класс данных:
data class CourseList(
val courseTitle: String,
val courseType: String,
val courseLength: String,
val target: Class<out Activity>
)
CourseListActivityHE:
CourseListActivityHe : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.course_list)
val course = listOf(
CourseList("BSc (Hons) Networking", "Type: Full/Part Time", "Length: 3/6 Years", CourseViewActivityHe1::class.java),
CourseList("BSc (Hons) Software Engineering", "Type: Full/Part Time", "Length: 3/6 Years", CourseListActivityHe::class.java),
CourseList("BSc (Hons) Civil Engineering PM", "Type: Full/Part Time", "Length: 3/6 Years", CourseListActivityHe::class.java),
CourseList("Level 4 Electrical Engineering", "Type: Full/Part Time", "Length: 1/2 Years", CourseListActivityHe::class.java),
CourseList("Level 4 Mechanical Engineering", "Type: Full/Part Time", "Length: 1/2 Years", CourseListActivityHe::class.java),
CourseList("Level 5 Electrical Engineering", "Type: Full/Part Time", "Length: 2/4 Years", CourseListActivityHe::class.java),
CourseList("Level 5 Mechanical Engineering", "Type: Full/Part Time", "Length: 2/4 Years", CourseListActivityHe::class.java),
CourseList("BSc (Hons) Ophthalmic Dispensing", "Type: Full/Part Time", "Length: 3/6 Years", CourseListActivityHe::class.java),
CourseList("FdSc Ophthalmic Dispensing", "Type: Full/Part Time", "Length: 2/4 Years", CourseListActivityHe::class.java)
)
list_of_course.apply {
layoutManager = LinearLayoutManager(this@CourseListActivityHe)
adapter = CourseListAdapter(course){
startActivity(Intent(this@CourseListActivityHe, it.target))
}
}
CourseListAdapter (при необходимости):
class CourseListAdapter( val course: List<CourseList>, val courseClicked: (CourseList) -> Unit):
RecyclerView.Adapter<CourseListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutView = LayoutInflater.from(parent.context).inflate(R.layout.course_list_activity, parent, false)
return ViewHolder(layoutView)
}
override fun getItemCount() = course.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val cours = course[position]
with(holder.view) {
setOnClickListener{
(courseClicked)(cours)
}
}
holder.view.courseTitle.text = "${cours.courseTitle}"
holder.view.courseType.text = "${cours.courseType}"
holder.view.courseLength.text = "${cours.courseLength}"
}
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view)
}