0

I have a button within a relative layout, and want it to create a new EditText in a different relative layout when pressed (a completely new EditText, not just turning the visibility on/off). This answer has helped, however I cannot change it to make it add an EditText instead of adding a new TextView. I don't need it to save the text inside any views or anything, just create another EditText, similar to an add contact button.

Community
  • 1
  • 1
LunarLlama
  • 229
  • 2
  • 11
  • 1
    To be clear, you are working in java swings. Right? If yes and by EditText, did you mean JTextField? Sorry I didn't quite understand the question. Btw, if you are working in android then please tag 'android' in your question. – Sanjeev Dhiman Aug 25 '16 at 05:23
  • absolutely you are working on android `Relative layout` , `EditText` and `TextView` are the terms of Android. So, Why not you included android tag ? – Inzimam Tariq IT Aug 25 '16 at 06:27

1 Answers1

1
private EditText createNewEditText() {
    final LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final EditText edittext = new EditText(this);
    Editext.setLayoutParams(lparams);
    return edittext;
}

just make new relative in xml file

add this edittext like this

rl.addView(createNewEditText());
Harpz
  • 183
  • 1
  • 12