• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arraylist keeps overwriting the last entry i added  RSS feed

 
Javier Coronel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for troubling you, i am new at android, and i need a little help. I am doing a simple ampplication in which you sign up some people to a club. What it keeps happening is that the last person i add to the arraylist overwries the old one. I really don´t know what it could be. If you can help i would be grateful. I know that right now what i am doing is only changing the object's content, but i don´t know how to fix it.

AltaSocio.java



Socios.java

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only ever create one Socios object (on line 26 of the first class) and then in your grabar method you edit this object - the same one every time. you should be creating a new Socios at the start of the grabar method.
 
Javier Coronel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote:You only ever create one Socios object (on line 26 of the first class) and then in your grabar method you edit this object - the same one every time. You should be creating a new Socios at the start of the grabar method.



How can i do that? I thought to do this:



but it didn´t work. How can i create a new Socios without losing the what the user has input?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch


I have had to edit your posts because the lines were too long. You can see how you should do it.
Stuart has told you what the problem is; I think adding new Socios(…) will probably work, yes.
 
Javier Coronel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch


I have had to edit your posts because the lines were too long. You can see how you should do it.
Stuart has told you what the problem is; I think adding new Socios(…) will probably work, yes.



Hello, sorry for bothering you, i am very fresh in this. But i mean apart from "nuevosSocio" i should create a new Socio in "grabar", if that is the case how do i put in the new one what the user has input in "nuevosSocio"?. Sorry for my english i am from Uruguay.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javier Coronel wrote:How can i do that? I thought to do this:



but it didn´t work. How can i create a new Socios without losing the what the user has input?

Instead of getting the values from the Socios object you created at line 26 you should be using the values you were using in the grabar method.
So it should be something like

 
Javier Coronel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote:
Javier Coronel wrote:How can i do that? I thought to do this:



but it didn´t work. How can i create a new Socios without losing the what the user has input?

Instead of getting the values from the Socios object you created at line 26 you should be using the values you were using in the grabar method.
So it should be something like





Thanks you very much for your replay again. I found the error yesterday, it was in the singleton. Every time i called the arraylist socio i overwrite the last one. I fixed there and its working fine.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!