I have a LinearLayout
which contains many Views (Button
s and TextView
s) and I want to make every view inside it unclickable until I process the server request. How can I do that?
Asked
Active
Viewed 1,055 times
-2

Ahmed Abdalla
- 2,356
- 2
- 14
- 27
-
You may achieve what you want by looking at [How to get all child view](https://stackoverflow.com/questions/7784418/get-all-child-views-inside-linearlayout-at-once) and [setClickable() doc](https://developer.android.com/reference/android/view/View#setClickable(boolean)) – vincrichaud Mar 08 '19 at 16:49
2 Answers
0
You can try
myView.setEnabled(false);
or
myView.setClickable(false); myView.setFocusable(false);
Basically an enabled false
doesn't respond to any response and a clickable false
still responds when setting at runtime.

Kashish Sharma
- 749
- 8
- 18
0
You can put your LinearLayout inside a Relative, and then add another Relative above your linear, with clickable = true.
I suggest you also add a progressbar, and maybe some background opacity so the user knows its loading. So when you are waiting for the request you set the relative that contains the progressbar visibility to visible, and when it has finished you set it back to gone.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-Add your elements-->
</LinearLayout>
<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/semi_gray"
android:clickable="true"
android:visibility="gone">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="@dimen/spacing_mid_large"
android:layout_height="@dimen/spacing_mid_large"
android:layout_centerInParent="true"
android:indeterminate="true"
android:visibility="visible" />
</RelativeLayout>
</RelativeLayout>

Agustin Pazos
- 131
- 7