How to layout views programatically in Android : Im trying to add a linear layout programtically thats width is calculated by a constraint vertical guideline. But nothing is added to the layout. I know that I need to add my views first and clone the whole layout and then start linking each element but I dont even think my guideline is being created. The custom control is used as a booking creator where users can select dates and the ui loads intervals of where the user can book.

How can I debug this? and where did I go wrong?

fragment.java

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.booker, container, false);  return rootView;  
    }

Fragment.xml:

    <android.support.constraint.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:app="http://schemas.android.com/apk/res-auto" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@color/color_logo_sign_up" 
        android:orientation="vertical"> 
    
        <TextView 
            android:id="@+id/textView_Date" 
            android:layout_width="0dp" 
            android:layout_height="0dp" 
            android:gravity="center_horizontal" 
            android:text="Date" 
            android:textAppearance="@style/TextAppearance.AppCompat.Large" 
            android:textSize="36sp" 
            android:textStyle="bold" 
            app:layout_constraintBottom_toTopOf="@+id/textView_Month" 
            app:layout_constraintEnd_toEndOf="parent" 
            app:layout_constraintStart_toStartOf="parent" 
            app:layout_constraintTop_toTopOf="parent" />  
    
        <TextView 
            android:id="@+id/textView_Month" 
            android:layout_width="0dp" 
            android:layout_height="0dp" 
            android:gravity="center_horizontal" 
            android:text="Month" 
            android:textAppearance="@style/TextAppearance.AppCompat.Large" 
            android:textSize="24sp" android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/recyclerView4" 
            app:layout_constraintEnd_toEndOf="parent" 
            app:layout_constraintStart_toStartOf="parent"   
            app:layout_constraintTop_toBottomOf="@+id/textView_Date" />  
    
       <android.support.v7.widget.RecyclerView 
            android:id="@+id/recyclerView4" 
            android:layout_width="match_parent" 
            android:layout_height="0dp"     
            app:layout_constraintBottom_toTopOf="@+id/guideline17" 
            app:layout_constraintEnd_toEndOf="parent" 
            app:layout_constraintStart_toStartOf="parent"          
            app:layout_constraintTop_toBottomOf="@+id/textView_Month" />  
    
        <com.techcloud.abdul.stutor.BookerView      
            android:layout_width="0dp" android:layout_height="0dp" 
            app:layout_constraintBottom_toBottomOf="parent" 
            app:layout_constraintEnd_toEndOf="parent" 
            app:layout_constraintStart_toStartOf="parent" 
            app:layout_constraintTop_toTopOf="@+id/guideline17"/> 
    
        <android.support.constraint.Guideline 
            android:id="@+id/guideline17" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:orientation="horizontal" 
            app:layout_constraintGuide_percent=".4" />   
    </android.support.constraint.ConstraintLayout> 

Booker.java

    public class BookerView extends ConstraintLayout { 
    Context context; 
    AttributeSet attributeSet; 
    
    public BookerView(Context context, @Nullable AttributeSet attrs) { 
        super(context, attrs);     
        this.context = context;     
        this.attributeSet = attrs;       
        init(context, attrs); 
    } 
    
    @Override 
    protected void onLayout(boolean changed, int l, int t, int r, int b) { 
        super.onLayout(changed,l,t,r,b); 
    } 
    
    private void init(Context context, AttributeSet attrs) { 
        int hours = 18; // starting at 6 am and ending at 12am 
        int width = getWidth();     
        int rowHeight = 100;      
        int id = 100; 
        LinearLayout linearLayoutTime = new LinearLayout(context);        
    
        linearLayoutTime.setBackgroundColor(getResources().getColor(R.color.colorPrimary));     
        linearLayoutTime.setId(id); 
    
        linearLayoutTime.setOrientation(LinearLayout.VERTICAL); int guideLineID = 101; 
        linearLayoutTime.setLayoutParams(new Constraints.LayoutParams(LayoutParams.MATCH_CONSTRAINT, LayoutParams.MATCH_CONSTRAINT));  
    
        ConstraintSet set = new ConstraintSet(); 
        int amountOfIntervalsPerHour = 1;
    
        if (attrs != null) { 
            TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.BookerView, 0, 0);    
    
            amountOfIntervalsPerHour = a.getInt(R.styleable.BookerView_amtOfIntervals,1); 
        } 
        
        addView(linearLayoutTime); 
        set.clone(this); 
        set.create(guideLineID, ConstraintSet.VERTICAL_GUIDELINE); 
        set.setGuidelinePercent(guideLineID, 0.5f); 
        set.connect(100, ConstraintSet.LEFT, this.getId(), ConstraintSet.LEFT, 0); 
        set.connect(100, ConstraintSet.RIGHT, guideLineID, ConstraintSet.RIGHT, 0); 
        set.connect(100, ConstraintSet.BOTTOM, this.getId(), ConstraintSet.BOTTOM, 0); 
        set.connect(100, ConstraintSet.TOP, this.getId(), ConstraintSet.TOP, 0); 
        set.applyTo(this); 
    }  
    }