0

I'm trying to make an "Add contact" activity. The user will be able to insert multiple phone numbers and multiple physical addresses for each user (probably up to 5 is enough), as seen below. Pressing the blue "+ Add.." button will create a field, which can then be deleted by pressing the 'x' on its right hand side.

I've tried creating these fields statically, and hiding/showing them upon clicking the buttons, but I don't like this approach (primarily because if I delete an entry in the middle, and an entry exists after it, it won't move to take the previous entry's spot).

How can I create, as well as add/remove, these EditTexts dynamically?

enter image description here

EDIT: Also, each address field will look like so:

enter image description here

George
  • 389
  • 5
  • 17
  • use recyclerview to achieve your functionality – niceumang Feb 27 '20 at 13:01
  • better to add views dynamically, eg: `addView()` method for LinearLayout parent. You can also look at this answer: https://stackoverflow.com/questions/6216547/android-dynamically-add-views-into-view – Vipul Asri Feb 27 '20 at 13:03
  • @VipulAsri will the top answer in the suggested question keep track of the position of each dynamically added view (so that on pressing each view's delete button it will correctly re-order the visible views)? – George Feb 27 '20 at 13:09
  • you can do the same thing with linear layout as well, using `removeViewAt()` method as well. My answer was based on ease of use and implementation because with RecyclerView you will introduce the problem of handling multiple views. – Vipul Asri Feb 27 '20 at 13:16

0 Answers0