There are 2 fragments: in the first fragment, when you click on the button, an entry is created in the table with some filled fields, and in the second fragment, I want to continue editing this entry. where is the mistake?

DataBaseHelper db= new DataBaseHelper(getActivity()); Order order = new Order("photo1","photo2",null,null,null,null,null,null,null,null,null); db.addApplicaions(order); ID=order.get_id(); 

then transfer the data to another fragment:

  bundle.putInt("id",ID); checkData.setArguments(bundle); 

and in the second I get them, but the trouble is that here: ID=order.get_id(); always value 0, as I understand it

  • How exactly do you get the data in the second fragment - pavlofff
  • show addApplicaions() method - temq

1 answer 1

ID, most likely, is assigned to you automatically for each new record in the database. In the instance of the Order class you created, this information is not there, because it has nothing to do with the database.
You need to return it from the addApplication method and assign it to an ID variable. This will help you to know that the insert method just returns the id recorded string

 long id = db.insert(...); 
  • Tell me how to correctly update the record? that is, in fragment 2, I need to update 3 fields, I updated the question. - Sergey
  • @ Sergey, ask it as a separate question. And so, like, you need to get the data object from the database, change it, and write it back. - JuriySPb