Reputation: 541
Here I've got this code
switchact.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent act2 = new Intent(view.getContext(), Activity2.class);
startActivity(act2);
}
});
And i've got image on my activity/layout1. How do I make that when I click on the image it switched to activity 2?
Upvotes: 1
Views: 2531
Reputation: 36
You should set a listener on the image over the onClick event, try something like:
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent act2 = new Intent(view.getContext(), Activity2.class);
startActivity(act2);
}
});
Upvotes: 1
Reputation: 2618
ImageView img = (ImageView) findViewById(R.id.myImageId);
img.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent act2 = new Intent(Activity1.this, Activity2.class);
startActivity(act2);
}
});
Upvotes: 0
Reputation: 3339
Intent act2 = new Intent(Activity1.this, Activity2.class);
startActivity(act2);
Upvotes: 1