используйте ниже код
Добавить этот файл Java ..
LinearLayout linearLayout = findViewById(R.id.editTextContainer);
Button btnShow = findViewById(R.id.btnShow);
if (btnShow != null) {
btnShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Create EditText
final EditText editText = new EditText(this);
editText.setHint(R.string.enter_something);
editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
editText.setPadding(20, 20, 20, 20);
// Add EditText to LinearLayout
if (linearLayout != null) {
linearLayout.addView(editText);
}
}
});
}