Code:
for (int i=0; I & lt; 4. I + +) {
OneNetApi. SetAppKey (KeyList. Get (I));
OneNetApi. QuerySingleDevice (IDList. Get (I), the new OneNetApiCallback () {//callback function
@ Override
Public void onSuccess (String response) {
JsonObject resp=new JsonParser (). The parse (response). GetAsJsonObject ();
Int errno=resp. Get (" errno). GetAsInt ();
If (0==errno) {
MDeviceItems. Add (resp. Get (" title "). GetAsString ());
MAdapter. SetNewData (mDeviceItems);
}
}
@ Override
Public void onFailed (Exception e) {
.
}
CodePudding user response:
This must have 4 times request, you can print a 4 times returned as a result, you setNewData adapter (mDeviceItems) method of how to write, I doubt you is direct assignment, not the addCodePudding user response:
Request is four times that's right, but the request is performed for the main thread, basic no time interval, so at the time of the query, a look have had a request directly cancel the last request, so they will only have one last request, I don't understand why a list of data need to request four times, this is bad design, have to write this way, can increase the interval of the request, such as a request over to start on the second, the method has a lot of kinds, counter, what variables can be,