title: Locating a button from outside its activity
body: <p>I have Firebaselistener class and it listens for the value of 1. When this value is reached I want the button drawable to change. Originally I had this all set up in my main activity and it worked OK using:</p>
  <pre><code>if(dls==1){
  m.setBackground(getResources().getDrawable(R.drawable.buttonbkground2));
  }
  </code></pre>
  <p>from with in my main activity using a valueEventlistener and listening for the value.</p>
  <p>But now I've set up a class to do the same thing I can't access the button ids from the main activity.</p>
  <pre><code>public class RewardValueListener  implements ValueEventListener {
  
  FirebaseAuth mAuth;
  String userid;
  int i;
  View view;
  String dls;
  Button mButton;
  Context c;
  
  public RewardValueListener() {
  
  }
  
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
  
      mAuth = FirebaseAuth.getInstance();
      FirebaseUser user = mAuth.getCurrentUser();
      userid = user.getUid();
      dls = dataSnapshot.child(userid).child(&quot;counter&quot;).getValue(String.class);
      Log.d(&quot;tag&quot;, &quot;Value: &quot; + dls);
      i = Integer.parseInt(dls);
      if (i == 1) {
  
          Log.d(&quot;tag&quot;, &quot;Congrats &quot; + i);
  
  
          mButton.setBackground(c.getResources().getDrawable(R.drawable.buttonbkground2));
  
      }
  }
  @Override
  public void onCancelled(FirebaseError firebaseError) {
  
  }
  </code></pre>
  <p>***Code edit with cricket's answer included</p>
  <pre><code>  public void getButton(Button button,Context context) {
      mButton = button;
      c=context;
    }
  </code></pre>
  <p>I know it's something to do with calling the view but how and where do I call it?</p>
  <h2>Edit</h2>
  <p>Thanks to @cricket_007 for his answer which works great. Now I have the code working is there away to call my Listener class to change all the buttons in my main activity rather than just one.</p>
  <p>I can get it to work if for every button if write the code this way but is there a way to condense it so I don't have to overflow my main activity:</p>
  <pre><code>  RewardValueListener reward1 = new RewardValueListener();
      mListref.child(&quot;RewardsSystem&quot;).addValueEventListener(reward1);
      reward1.getButton(mstreaming,mcontext);
      RewardValueListener reward2 = new RewardValueListener();
      mListref.child(&quot;RewardsSystem&quot;).addValueEventListener(reward2);
      reward2.getButton(mcustom,mcontext);
      RewardValueListener reward3 = new RewardValueListener();
      mListref.child(&quot;RewardsSystem&quot;).addValueEventListener(reward3);
      reward3.getButton(mlauncher,mcontext);
      RewardValueListener reward4 = new RewardValueListener();
      mListref.child(&quot;RewardsSystem&quot;).addValueEventListener(reward4);
      reward4.getButton(mmovies,mcontext);
    etc etc...
  </code></pre>