I\'ve got a viewPager, and in second page i\'ve got a button. I want it to do something onClick but it\'s not doing.
I\'ve done on xml file: android:onClick=\"butto
I see a few problems with your code:
onSaveInstanceState aside from...saving state. onSaveInstanceState is only called when the activity is about to be paused; it will not be called until then, therefore attaching a listener in there will not do anything. :(btn.setOnClickListener(this) unless your ViewPagerProjectActivity implements onClickListener. So you could implement that, or just use the code below.Move this code into onCreate after setContentView(R.layout.main):
Button btn = (Button) findViewById(R.id.button1);
OnClickListener listener = new OnClickListener(){
@Override
public void onClick(View v) {
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
}};
if (btn != null)
btn.setOnClickListener(listener);