I try to set the Tag with the ID of one of my buttons:
int boeserzufall = (int) (Math.random()*23);
Button boese = arr.get(boeserzufall);
boese.setBackgroundResource(R.drawable.williboese);
boese.setTag(R.drawable.williboese);
That works fine, boese.getTag()
brings me the correct id. arr
is an ArrayList<Button>
that contains all my buttons.
Now in my OnClick() method I want to check if the current button has the same resId as boese
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
count++;
int resId = (Integer) arg0.getTag();
if(resId == R.drawable.williboese) {
Toast.makeText(MainActivity.this, "heeeee", Toast.LENGTH_SHORT).show();
}
}
});
My problem is that I get a Nullpointer Exception when I try read arg0.getTag()
Edit:
First, I take a random button out of my array and therefor I want to set the background image with R.drawable.williboese
.
So on one of my 25 buttons I have a different background image than on the others. This one I have to find and react different than on the others...