I am new to android development. I have a question. Can I add data to the same field with different names in the Cloud Firestore in Android Studio? For example, the user enters his name and selects the area in the Spinner and clicks "Add." The data should fall into one collection and field in the Cloud Firestore. The code below shows how to add data to different collections:
btn_setData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> nameMap = new HashMap<>(); Map<String, String> spinnerMap = new HashMap<>(); nameMap.put("name", et_setName.getText().toString()); spinnerMap.put("district", sp_selectDistrict.getSelectedItem().toString()); mFirestore.collection("users").document().set(nameMap).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ Toast.makeText(SelectLocationActivity.this, "Запись прошла успешно", Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(SelectLocationActivity.this, "Запись не удалась", Toast.LENGTH_SHORT).show(); } } }); mFirestore.collection("users_district").document().set(spinnerMap).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ Toast.makeText(SelectLocationActivity.this, "Запись прошла успешно", Toast.LENGTH_SHORT).show(); } } }); } }); Is it possible to combine these two actions? Or with the type "Object" in the database when creating a field. Thank.
