Change ImageView image inside onClick event
<p>I have an ImageView working as a button in my program. I need it to be an ImageView since I want just the image to be shown, not the borders.</p>

<p>This button is a lamp, if the data in database says it's visible, the lamp must be "on", when you click the button, it will check the data from bank and change it to "off" if it's on and vice-versa.</p>

<p><strong>So, the change of image will happen inside a onClick event.</strong></p>

<p>Here is my code:</p>

<pre><code>btnVisualizar.setClickable(true); 
btnVisualizar.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        try {
            if (visivelBanco.getText().equals("Y")) {
                btnVisualizar.setImageResource(this.getResources().getIdentifier(
                    "drawable/visible_off", null, this.getPackageName()));
            } else {
                btnVisualizar.setImageResource(
                    this.getResources().getIdentifier("drawable/visible_on", null, this.getPackageName()));
            }
        } catch (Exception e) {
            Toast.makeText(
                getBaseContext(), 
                "Falha ao modificar visibilidade do item!", 
                Toast.LENGTH_SHORT).show();
        }
    }
});
</code></pre>

<p>However the compiler doesn't recognize the method getResources() and getPackageName().</p>

<p>What am I doing wrong?</p>

<p>Any help is appreciatted.</p>
