Suppose I have this pink box:
It consists of LinearLayout
with its children: TextView
as field name and an EditText
. EditText
is intentionally disabled. What I want is that, user can click wherever user wants on that pink box. By the way, please just ignore any UI/UX things that you found weird.
I've tried, but user can't tap the area that EditText
occupies. User have to tap in TextView
or blank area on pink box so that the apps got the 'click'. But if user taps on EditText
's area, nothing will happen.
I've tried playing with some things in xml's properties, such as set LinearLayout
's clickable
to true
, and all children or just EditText
's properties of clickable
, focusable
, and focusableInTouchMode
to false
, all to no avail. EditText
area still cannot be clicked.
Any idea? Can't it be reached just through xml? Should it be done programmatically just to turn bypass EditText
's click?
You need to request the parent layout (LinearLayout, whatever) and loop through the views if you dont want to bind them all. If you use databinding its easier. Anyway, here is a solution (a small piece of code is required!).
Layout:
Code:
If you dont like boilerplate you may also use lambda (use 1.8 features)
If you use at least API 24 you can even make it shorter:
You can simply add onTouch Listener instead of click Listener.