title: Using variables value outside the method
body: <p>I'm stuck with passing variable values outside the method. Example:</p>
  
  <pre><code>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();
              }
  </code></pre>
  
  <p>and i want to use received in method value further: textview.setText(createdByName).</p>
  
  <p>Also another example:</p>
  
  <pre><code>ServiceSpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                  if(parent.getItemAtPosition(position).equals("Pick a service name")){
  
                  }
                  else{
  
                      String ServiceName = parent.getItemAtPosition(position).toString();
                  }
              }
  </code></pre>
  
  <p>And outside the method i want to:</p>
  
  <pre><code>AddRequest items = new AddRequest(ServiceName);
  FirebaseDatabase.getInstance().getReference("Requests").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(items)
  </code></pre>
  
  <p>As i undestand use local variable more correct, but i anyway dont know how to get this value outside the method.</p>