Home:ALL Converter>Retreive data from a certain position in firebase using Android Studio

Retreive data from a certain position in firebase using Android Studio

Ask Time:2018-09-09T23:53:50         Author:dunkiero

Json Formatter

Hey people :) I am very new to programming and just got my head around using RecyclerView in Android Studio.

Now I would like to retreive data from a position x in firebase:

So for example my Database includes:

Users: Max (with the fields: University, Age, City) Lena (with the fields: University, Age, City)

I don't know how many users there are and whats their name and I'd like to get all the data of one User at position x.

Is there anybody who has an idea how to solve that problem? Thanks in advance!

EDIT: I now saved the UID from the User and passed it to the other activity. Then I am trying to receive the belonging data from firebase, but I am still not able to show the data from the Field "university" in the TextView.

public class nextActivity extends AppCompatActivity{

String UID;
private DocumentReference myReference;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next_activity);

//get data from intent (I checked the value of UID - getIntent worked.)
UID = getIntent().getStringExtra("uid");

// I am not sure with the following line. Is it possible to just add "UID"?
myReference = FirebaseFirestore.getInstance().document("Users/"+UID);
myReference.addSnapshotListener(new EventListener<DocumentSnapshot>() {
    @Override
    public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
        if (documentSnapshot.exists()) {

            long universityID = documentSnapshot.getLong("university");
            cUniversityText.setText("University"+Long.toString(universityID));

        } else if (e != null) {
            Log.w("InspiringQuote", "Exception!", e);
        }
    }
});
cUniversityText = findViewById(R.id.cuniversitytext);

}

Author:dunkiero,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52246212/retreive-data-from-a-certain-position-in-firebase-using-android-studio
yy