tags:

views:

67

answers:

1

I am using layout xml documents for my ui controls.

I need to create and remove these controls (input fields) on the fly, based on how many results I get back from my database.

For each group, there can be 0..* fields and these are prepopulated from the database.

Also, it would be good if I can invoke a method to create an additional field; something like the address book, where you can click + or - to add or remove a phone or other detail.

In a "psuedo" style, I'm guessing something like this:

  1. Check database - How many of X are there [y]?
  2. Create Y fields.

The user may then add new fields, so once I click submit i need to apply all of that to database.

Any examples or hints greatly welcomed. Hope this make sense! :)

+1  A: 

I recommend doing this in code, XML is more for interfaces that don't have changing numbers of fields, unless your adding items to a view like a ListView. Then you just have to use

view.addView(child);

You may, or may not, want to create a custom list adapter for your database. You can find some great tutorials by searching Custom list adapters in google.

Con
Could I place an input field and label within a listview?I am trying to make something that is very similar to the edit contact screen on Android address book.
Sochin