I\'m trying to create a simple flashlight app in order to learn android development. I\'m trying to get it so that when when you click on the light ImageView object it changes t
you do not need to declare a variable light in the handler
public class flash extends ActionBarActivity {
public Boolean on = false;
ImageView light;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flash);
light = (ImageView) findViewById(R.id.light);
light.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(on){
light.setImageResource(R.drawable.flash_off);
on = false;
}else{
light.setImageResource(R.drawable.flash_on);
on = true;
}
}
});
}