OriginallySource codeAs follows:
List <restaurant> model; // a custom list data that stores the custom lunchlistadapter; // a custom listview adapter ...... // class onsavereimplements onclicklistener {// listener for button save is omitted. After clicking it, add the data restaurant r = new restaurant () to the model (); // ② @ overridepublic void onclick (view v) {R. setname (name. gettext (). tostring (); R. setaddress (ADDR. gettext (). tostring (); Switch (types. getcheckedradiobuttonid () {case R. id. take_out: R. settype (take_out); break; case R. id. sit_down: R. settype (sit_down); break; case R. id. delivery: R. settype (delivery); break;} model. add (r); // ① }}
The problem is that after you click "Storage", if Adapter. Add (R) is used at ① );
The items displayed in the listview are all stored at the end, and the output content from the model is the same after the item is clicked,
If Model. Add (R) is used at ① );
The items displayed in the listview are correct, that is, the order of the content you store. However, after you click the item, the content read from the model is the same as that shown above, all are the last stored data,
I don't know how to figure it out if I want to, but I finally want to figure it out.CodeIt is defined in onclick, so that no matter which method is used, the display and output results are correct.
For the moment, I think that the data added to the R model defined in section ② may be overwritten, but it is still a bit confused. I would like to write down this impression first.