private ArrayList<String> idRecords = new ArrayList<>();
i try to put string in here but, when i using db.collection(collection).whereEqualTo(fields, values).get
private void getIdRecords(){
db.collection("records")
.whereEqualTo("idUsers", user.getUid())
.whereEqualTo("status", "progress")
.get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
idRecords.add(document.getId());
}
} else {
Log.d("get Id Records : ", "Error getting documents: ", task.getException());
}
});
}
it cant assign the value to ArrayList full code below :
public class WorkOffActivity extends AppCompatActivity {
private ArrayList<String> idRecords = new ArrayList<>();
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private FirebaseUser user = mAuth.getCurrentUser();
private TextView tv_times, tv_activity, tv_place, tv_startDate;
private Button btn_draft, btn_cancel, btn_finish;
private EditText et_progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_off);
getIdRecords();
initializeComponent();
setTextComponent();
}
private void initializeComponent() {
tv_times = findViewById(R.id.offWork_tvTimes);
tv_activity = findViewById(R.id.offWork_tvActivity);
tv_place = findViewById(R.id.offWork_tvPlace);
tv_startDate = findViewById(R.id.offWork_tvStartDate);
et_progress = findViewById(R.id.offWork_etProgress);
btn_draft = findViewById(R.id.offWork_btnSaveTemp);
btn_cancel = findViewById(R.id.offWork_btnCancelActivity);
btn_finish = findViewById(R.id.offWork_btnFinishActivity);
}
private void getIdRecords() {
db.collection("records").whereEqualTo("idUsers", user.getUid())
.whereEqualTo("status", "progress")
.get()
.addOnCompleteListener(task -> {
String temp = null;
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
temp = document.getId();
}
idRecords.add(temp);
} else {
Log.d("get Id Records : ", "Error getting documents: ", task.getException());
}
});
}
private String[] getDataRecords(){
String[] recordsData = new String[6];
db.collection("records").document(idRecords.get(0))
.get().addOnCompleteListener(task -> {
DocumentSnapshot doc = task.getResult();
recordsData[0] = doc.getString("activity");
recordsData[1] = doc.getString("idUsers");
recordsData[2] = doc.getString("idWorkspaces");
recordsData[3] = doc.getString("progress");
recordsData[4] = doc.getString("status");
recordsData[5] = doc.getString("times");
});
return recordsData;
}
private void setTextComponent() {
Toast.makeText(getApplicationContext(), idRecords.get(0), Toast.LENGTH_SHORT).show();
}
i cant take the value from that array with this idRecords.get(0)