在向其中插入数据期间如何阻止检索ArrayList项目

问题描述 投票:-1回答:1

我想在创建Mapview并使用标记将这些商店插入地图时获得商店位置,为此,我需要将数据库元素插入ArrayList并检索那些信息(以使用它删除Makers和... ),但是当我使用调试程序时,发现插入之前检索信息已完成。我不知道为什么,但是重新获取数据库信息可能需要一些时间,因此我需要一个解决方案。

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<>();
                //In this point we got our hero list
                //thats damn easy right ;)
                //List<col> heroList = response.body();
                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>();

                }
                //now we can do whatever we want with this list

            }
android arraylist
1个回答
0
投票
您需要在getd(...)中添加一些回调例如

private interface MarkerLoadCallBack { void done(List<col> cols); } private void getD(String selector, MarkerLoadCallBack markerLoadCallBack) { 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<>(); //In this point we got our hero list //thats damn easy right ;) //List<col> heroList = response.body(); 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>(); } markerLoadCallBack.done(colList); } }); }

热门问题
推荐问题
最新问题