0
私はGoogle Cloud Firestore
を使用してアプリケーションのデータを保存していますが、そのデータを取得してArrayList
を入力しようとしています。Java/Android - 匿名の内部クラスでArrayListを更新
ArrayListは匿名の内部クラスで正常に更新されますが、匿名の内部クラスを含むメソッドを呼び出した後にArrayList
を使用すると(以下のログ呼び出しでその内容をテストするだけでなく) )、空として表示されます。
私はこの1つに私の髪を引っ張ってきた - 任意の助けに感謝!
ありがとうございました。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mCostsArrayList = new ArrayList<>();
//Get costs and sales data from Cloud FireStore - updates mCostsArrayList & mSalesArrayList
getCostTransactions(costsCollectionRef);
//Gets Cloud Firestore costs transactions and puts to mCostsArrayList
private void getCostTransactions(CollectionReference collectionReference){
collectionReference.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
if (documentSnapshots.isEmpty()){
Log.d(TAG, "OnSuccess: LIST EMPTY");
return;
} else {
//Convert the whole Query Snapshot to a list of objects
//Do not need to fetch each document
List<BandTransaction> costs = documentSnapshots.toObjects(BandTransaction.class);
mCostsArrayList.addAll(costs);
Log.d(TAG, "onSuccess" + mCostsArrayList);
return;
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getActivity(), "Error getting data", Toast.LENGTH_SHORT).show();
}
});
Log.d(TAG, "AFTER METHOD" + mCostsArrayList);
}