I'm stuck with passing variable values outside the method. Example:
usernameRef = FirebaseDatabase.getInstance().getReference().child("Users").child(uid).child("Name");
usernameRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String createdByName = dataSnapshot.getValue().toString();
}
and i want to use received in method value further: textview.setText(createdByName).
Also another example:
ServiceSpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(parent.getItemAtPosition(position).equals("Pick a service name")){
}
else{
String ServiceName = parent.getItemAtPosition(position).toString();
}
}
And outside the method i want to:
AddRequest items = new AddRequest(ServiceName);
FirebaseDatabase.getInstance().getReference("Requests").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(items)
As i undestand use local variable more correct, but i anyway dont know how to get this value outside the method.