How to set onClickListener to the WHOLE screen in Android?
android, fullscreen, onclicklistener, screen, textview
Solution
You can do this:
ViewTreeObserver viewTreeObserver = myView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {...}
From the docs of `ViewTreeObserver`:
A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass, touch mode change
Problem
The xml layout file looks like: ``` <?xml version="1.0" encoding="utf-8"?> <FrameLayout android:id="@+id/my_rootViewID" <LinearLayout> <ImageView/> <TextView/> <ImageView/> </LinearLayout> </FrameLayout> ``` I have tried this: ``` my_view = findViewById(R.id.my_rootViewID); my_view.setOnClickListener( new My_OnClickListener() ); ``` My problem: This works only with the ImageViews, but the TextView is not clickable. I could set OnClickListener specifically to the TextView as well, but I have many TextViews (in other cases), so adding theese listeners would be very slow, and elaborate.