I have extended ConstraintLayout and adding views programatically then setting constraint to each view. but some how its not working, only the first view is showing up. Unable to figure out where I went wrong.
addViews(){
titleInfoView = new TextView(getContext());
titleInfoView.setId(ViewCompat.generateViewId());
addView(titleInfoView);
editBoxView = new EditText(contextWrapper);
editBoxView.setId(ViewCompat.generateViewId());
addView(editBoxView);
notInfoView = new TextView(getContext());
notInfoView.setId(ViewCompat.generateViewId());
addView(notInfoView);
errorMessageView = new TextView(getContext());
errorMessageView.setId(ViewCompat.generateViewId());
addView(errorMessageView);
}
Then adding constraint to each view
private void addConstraintToViews() {
ConstraintSet set = new ConstraintSet();
set.clone(this);
//connect title view
set.connect(titleInfoView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
set.connect(titleInfoView.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
set.connect(titleInfoView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
//connect edit box
set.connect(editBoxView.getId(), ConstraintSet.TOP, titleInfoView.getId(), ConstraintSet.BOTTOM, R.dimen.margin_10);
set.connect(editBoxView.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
set.connect(editBoxView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
//connect info title
set.connect(notInfoView.getId(), ConstraintSet.TOP, editBoxView.getId(), ConstraintSet.BOTTOM, R.dimen.margin_10);
set.connect(notInfoView.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
set.connect(notInfoView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
//connect error messag
set.connect(errorMessageView.getId(), ConstraintSet.TOP, notInfoView.getId(), ConstraintSet.BOTTOM, R.dimen.margin_10);
set.connect(errorMessageView.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
set.connect(errorMessageView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
set.connect(errorMessageView.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
set.applyTo(this);
}
Only First item is showing up that is Title like this image. I want to add each view one after another and that how i wrote the constraintset. Can any one suggest what is getting wrong.