So what I have is a custom class that can be inherited by other Fragments.
The class has abstract variable - floatingView which is FrameLayout. So any Fragment that inherits this class will have a FrameLayout with X amount of child views - any kind.
Now, my question is - how can I set a click listener in this class with abstract view that holds X amount of child views that can be any type? Setting a simple click listener will always return FrameLayout (parent) id as the one that was clicked, not the child (I need the child one).
I have:
interface Listener {
fun onFrameLayoutClicked(view: View)
}
and set it up simply as:
frameLayoutParentView.apply {
setOnClickListener {
clickListener?.onFrameLayoutClicked(it) //This always return framelayout id and not the childs one (I need child id for logic)
}
}
Any not too hacky ideas?
I'm not sure about how dynamic is your layout in terms of adding/removing view. But if all childs are already placed You can iterate through child views and attach onClick listeners to them.
Here is also solution for adding listener for all nested views.