enter image description here

This is the code where the include is set:

<FrameLayout 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" tools:context="com.eranewgames.vkdownloader.fragments.GroupFragment"> <android.support.v7.widget.RecyclerView android:id="@+id/recView" android:background="@android:color/white" android:layout_width="match_parent" android:layout_height="match_parent"/> <include layout="@layout/loading_progress"/> 

loading_progress itself:

 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:layout_gravity="center" android:id="@+id/progressBar" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> </android.support.constraint.ConstraintLayout> 

 public class RestVkRequest { private Context context; private View viewProgress; public RestVkRequest(Context context) { this.context = context; viewProgress= LayoutInflater.from(context).inflate(R.layout.loading_progress,null); viewProgress.setVisibility(View.VISIBLE); } public void getVkGroups(){ VKRequest vkRequest= new VKRequest("groups.get", VKParameters.from("extended",1)); vkRequest.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); viewProgress.setVisibility(View.GONE); GroupsModel groupsModel=new Gson().fromJson(response.responseString,GroupsModel.class); EventBus.getDefault().post(new EventMessage(EventName.RESPONSE_GROUP,groupsModel)); } @Override public void onError(VKError error) { super.onError(error); viewProgress.setVisibility(View.GONE); } }); } } 

As seen in the picture, setVISIBLE does not work. What am I doing wrong?

  • one
    Not to that view appeal. You need to set the ConstraintLayout id in loading_progress.xml and get it using findViewByID() . - woesss
  • @woesss, Yes, damn it does not work! - user239760
  • Yes, damn, show how it does not work for you))) The code in the question is wrong - LayoutInflater creates a new twist and gives a link to it, and not to the one that is displayed on the screen - that's why you cannot control it. - woesss

1 answer 1

 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" >> android:id="@+id/loadingLayout" << android:layout_width="match_parent" android:layout_height="match_parent"> 

and in the loadingLayout.setVisibility code (View.GONE) when necessary. Just do not forget to bind before this (via ButterKnife, for example, or in the old way through findViewById

  • Still does not work. - user239760
  • Then add the parameter to the <include ... type itself. I have a layout in ConstraintLayout, so I need to change it to my version. - Dmitry K.
  • <include layout="@layout/holder_loading" android:visibility="invisible" android:id="@+id/layoutLoadingHolder" android:layout_height="0dp" android:layout_width="0dp" app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> - Dmitry K.