View.setBackground() configurando el fondo de ImageButton?

I have an ImageButton:


This is part of a seperate activity that is started from my main activity:

Intent intent = new Intent(this, BookRead.class);

Once in the new activity I call the NextPage method upon ImageButton click:

public void NextPage(View view)

'res' is defined in my new activity in the onCreate method:

res = this.getResources();

For some reason when I click my ImageButton it changes the background on the ImageButton itself instead of the activity layout.

preguntado el 03 de enero de 13 a las 15:01

Prueba a imprimir view. What does it return? It's probably passing in the button instead -

2 Respuestas

An imagebutton is also a view, and you are probably passing the imagebutton view to the NextPage method.

You could either get the correct view by referencing it from XML or do something like view.getParent().

Respondido el 03 de enero de 13 a las 15:01

That did it! Thank you!. I used: View parentView = (View)view.getParent(); Worked great! - Puntilla

The onClick method receives the view which is actually clicked.

Respondido el 03 de enero de 13 a las 15:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.