title: Java Android - Access variables outside addValueEventListener
body: <p>I want to know how to access the variable <code>totalAmount</code> outside the <code>mDatabase.addValueEventListener</code>.</p>
  <pre><code>    //This is inside onCreateView
      mDatabase.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
              totalAmount=0;
  
              for (DataSnapshot mySnapshot : dataSnapshot.getChildren()){
                  Transaction transaction = mySnapshot.getValue(Transaction.class);
                  totalAmount += transaction.getAmount();
              }
              String total_amount = String.valueOf(totalAmount);
              totalAmount.setText(total_amount);
          }
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
          }
      });
  
      TextView.setText(String.valueOf(totalAmount))
  </code></pre>
  <p>I can't find proper solution. Please help me with this.</p>