I have trouble adding data in ArrayList. I tried to add data in array list but got nothing
Here's my code
public class fmMain extends Fragment {
private ArrayList<markerList> posList = new ArrayList<markerList>();
public fmMain() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
//Firebase get data
stores.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (QueryDocumentSnapshot documentSnapshot: queryDocumentSnapshots){
markerList m = new markerList(documentSnapshot.getId());
posList.add(m);
}
Log.d(TAG,posList.toString()); //got value
}
});
Log.d(TAG,posList.toString()); //got nothing
}
as you can see when I tried to add value in function onSuccess I got value that has been added but when I tried to add outside function I got nothing