What I want to learn is,
When the button is clicked, a new plain text(editable) should appear below the default plain text I have created in the UI with the same properties as the default one(for example, same width, height) with some margin in between each one.
My project layout type is constraint layout, I wanted my buttons to be placed in the bottom right corner of the UI and I had archived that with the constraint one.
By browsing through stack Overflow and others through google,
All I saw is about adding plain text in a linear layout, if i switched from constraint layout to linear layout, my buttons get misplaced and not that I had at least implemented the functionality to add plain text with a click of the button with the linear layout.
that's why I am sticking to the constraint layout with this at least my buttons don't get misplaced, if there is any way in any layout can get me the result I want, I am open to it.
So far I done this
ConstraintLayout constraintLayout = findViewById(R.id.constraintLayout);
Button buttonAddNewToDo = findViewById(R.id.addNewToDo);
buttonAddNewToDo.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
EditText newToDo = new EditText(MainActivity.this);
newToDo.setLayoutParams(new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
newToDo.setHint("enter new to do");
constraintLayout.addView(newToDo);
}
});
the code is within the onCreate() FYI.
What the above code does is, when the button is clicked, it creates a new plain text, it's in the top left corner,
To see the UI for the above piece of code(see the image below)