1 回答

TA貢獻1853條經驗 獲得超18個贊
如果我理解正確:該listFavoriteLocation方法正確地從數(shù)據(jù)庫中檢索您期望的數(shù)據(jù)。如果您查看其余代碼,您會發(fā)現(xiàn)您正在迭代數(shù)據(jù)列表并用它們一個接一個地覆蓋您的實例變量,直到列表被完全迭代,這意味著您離開方法后,只會保留實例中的最后一個元素。
因此,需要明確的是,以下塊將正確記錄每個元素,但只有最后一個元素的值將保留在您正在使用的兩個實例變量中(FAVCurrentLocationLAT和FavCurrentLocationLong):
for (DataModel mo:data ) {
this.List_FAVCurrentLocationLAT = mo.getFAVCurrentLocationLAT();
this.List_FAVCurrentLocationLONG = mo.getFAVCurrentLocationLONG();
Log.i("helloLAT",""+List_FAVCurrentLocationLAT); //OK
Log.i("helloLONG",""+List_FAVCurrentLocationLONG); //OK
// This section writes the favorite locations seperately to the log.
}
您需要做的是使用方法data中加載的返回列表listFavoriteLocation,然后根據(jù)需要在以下代碼中對其進行操作。
因此,例如:
List<DataModel> data = listFavoriteLocation();
for (int i = 0; i < data.size(); i++) {
DataModel dataModel = data.get(i);
log.i("Data model "+i+": "+dataModel);
// Do work on each data model element here
}
添加回答
舉報