bb azeae
bb azeae

Reputation: 137

How to block retrieving ArrayList information during of inserting data into it

I want to get a stores position when I create Mapview and Insert those stores into a map using markers and to do this I need to insert database elements into An ArrayList and retrieve those informations ( for use it to remove Makers and...) but when I use debugging I found that retrieving Infos complete before inserting. I don't know why but maybe retrieving database infos takes time so I need a solution for that.

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());
        }

and 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>();

                }

            }

Upvotes: 0

Views: 30

Answers (1)

Rizwan
Rizwan

Reputation: 1664

Write marker insertion code in on response method. This method gets invokes once a response comes from server.

Refer below code :

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());
                }

            }
        }
    }

Upvotes: 1

Related Questions