I am getting an error when switching between views. I have android:onClick="onClick" on every Image button in the xml. Here is the code
selfHelp = (ImageButton)findViewById(R.id.selfhelpButton);
services = (ImageButton)findViewById(R.id.services);
messages = (ImageButton)findViewById(R.id.mailButton);
about = (ImageButton)findViewById(R.id.aboutButton);
more = (ImageButton)findViewById(R.id.moreButton);
selfHelp.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), SelfHelp.class);
startActivity(myIntent);
}
});
Services.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Services.class);
startActivity(myIntent);
}
});
messages.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Messages.class);
startActivity(myIntent);
}
});
about.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), About.class);
startActivity(myIntent);
}
});
more.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), More.class);
startActivity(myIntent);
}
});
I have had this working on another page with only one button but the image button doesn’t work. Any help will be great
you have two choices
android:onClick="onClick"on each ImageButton because youare already set click listener on your button on overriding the
default onClick() method.
remove all setOnclickListener() methods and in your ImageButtons add attributes:
in your Activity use: