0

I want my code to do as follows:

@Override
public void onClick(View v) {
    ...
    Firebase ref = new Firebase('url')
    ref.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
            // if one of the children fullfills a certain condition
            // throw a toast
            }
    }
}

The only problem is that I can't throw a toast because I am not within the context of the function.

How can I work around this?

Robert
  • 199
  • 1
  • 9
  • This works fine for me `Toast.makeText(MainActivity.this, "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();`. What problem are you having? – Frank van Puffelen Mar 27 '16 at 15:46
  • Excellent, it worked! Just a question - I know what 'this' does, but I have never seen the use of 'this' after a class (as in MainActivity.this). What does it do? – Robert Mar 27 '16 at 16:35
  • Also, let's say I have a variable before the ref variable. How do I change the value of that variable within onDataChange? – Robert Mar 27 '16 at 16:40
  • See http://stackoverflow.com/questions/3434041/meaning-of-this-and-class-in-java – Frank van Puffelen Mar 27 '16 at 16:49

0 Answers0