gpt4 book ai didi

java - 如何在向 ArrayList 插入数据期间阻止检索 ArrayList 信息

转载 作者:行者123 更新时间:2023-12-02 09:05:59 28 4
gpt4 key购买 nike

我想在创建 Mapview 时获得商店位置,并使用标记将这些商店插入 map 中,为此,我需要将数据库元素插入 ArrayList 并检索这些信息(用于删除制造商和.. .)但是当我使用调试时,我发现在插入之前检索信息已完成。我不知道为什么,但也许检索数据库信息需要时间,所以我需要一个解决方案。

public void onMapReady(GoogleMap googleMap) {
map = googleMap;
//----------------Get all col / vent collection
getd("all");

//---------------Setup Markers of col/vent-------------------//
ArrayList<MarkerData> mker = new ArrayList<MarkerData>();

for(int i = 0 ; i < mker.size() ; i++) {
Log.d("Date of arrays",mker.get(i).getDate());
}

和 getd()

private void getd(String selector){
/*ProgressDialog progress = new ProgressDialog(getActivity());
progress.setTitle("Charger les infos");
progress.setMessage("attendre...");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.show();*/
//Creating a retrofit object
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFactory to directly convert json data to object
.build();

Api api = retrofit.create(Api.class);

Call<List<col>> call = api.getHeroes(selector);

call.enqueue(new Callback<List<col>>() {
@Override
public void onResponse(Call<List<col>> call, Response<List<col>> response) {
mker = new ArrayList<>();
List<col> colList = response.body();for ( col c: colList){
Log.d("name : ",c.getNom_col());
Log.d("Lat : ",c.getLat_col());
Log.d("Long : ",c.getLong_col());
Log.d("Email : ",c.getEmailcol());
Log.d("type : ",c.getType());
Log.d("date : ",c.getDate_creation_col());
Log.d("Creator : ",c.getCreator());
mker.add(new MarkerData(c.getNom_col(),c.getLat_col(),c.getLong_col(),c.getEmailcol(),c.getType(),c.getDate_creation_col(),c.getCreator()));
//ArrayList<MarkerData> markersArray = new ArrayList<MarkerData>();

}

}

最佳答案

在响应方法中写入标记插入代码。一旦来自服务器的响应就会调用此方法。

引用下面的代码:

private void getd(String selector) {
/*ProgressDialog progress = new ProgressDialog(getActivity());
progress.setTitle("Charger les infos");
progress.setMessage("attendre...");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.show();*/
//Creating a retrofit object
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFactory to directly convert json data to object
.build();

Api api = retrofit.create(Api.class);

Call<List<col>> call = api.getHeroes(selector);

call.enqueue(new Callback<List<col>>() {
@Override
public void onResponse(Call<List<col>> call, Response<List<col>> response) {
mker = new ArrayList<>();
List<col> colList = response.body();
for (col c : colList) {
Log.d("name : ", c.getNom_col());
Log.d("Lat : ", c.getLat_col());
Log.d("Long : ", c.getLong_col());
Log.d("Email : ", c.getEmailcol());
Log.d("type : ", c.getType());
Log.d("date : ", c.getDate_creation_col());
Log.d("Creator : ", c.getCreator());
mker.add(new MarkerData(c.getNom_col(), c.getLat_col(), c.getLong_col(), c.getEmailcol(), c.getType(), c.getDate_creation_col(), c.getCreator()));
//ArrayList<MarkerData> markersArray = new ArrayList<MarkerData>();

}

// Marker retrieval code should be here
for (int i = 0; i < mker.size(); i++) {
Log.d("Date of arrays", mker.get(i).getDate());
}

}
}
}

关于java - 如何在向 ArrayList 插入数据期间阻止检索 ArrayList 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59810233/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com