0

I have an empty ListView where the user should be able to add each list item manually at the press of a button. When the user clicks on the button, I have a place holder list item appear which contains an EditText. When the user edits the text and it loses focus, I want the source data set to be updated with the users input.

Dynamically add elements to a listView Android

Up to now, I found this answer which uses an ArrayAdapter that connects an ArrayList and my ListView but from my understanding, this only updates the ListView when the ArrayList is updated. To clarify, I want to do the opposite, i.e when the list item is changed within the ListView, I want the appropriate ArrayList (or whatever data source which would make this easier) item to be updated.

I'd appreciate any help with this.

Thanks in advance!

Community
  • 1
  • 1
Adam
  • 472
  • 1
  • 7
  • 14
  • `when the list item is changed within the ListView`, how you make this happen? – Xcihnegn Apr 30 '15 at 05:53
  • My list items consist of EditText views. So when the user edits the text, I want it to change the content of my data set. – Adam Apr 30 '15 at 15:53
  • Yes you can set listener to EditText, when text changed then you can change the data in data list accordingly – Xcihnegn May 01 '15 at 06:09

1 Answers1

0

I would suggest storing the position you focus on, then when it loses focus, write the new data to the item in your arraylist by calling getItem(position); followed up by notifyDatasetChanged();

Nick H
  • 8,897
  • 9
  • 41
  • 64
  • I've thought of a few work around similar to this but my main reason for posting here was to find out if there is some sort of adapter that does this for me. I'll most likely go for this solution if I can't find anything that requires less work! Thanks a lot. – Adam Apr 30 '15 at 15:56