Reputation: 55
I am currently doing an android app which has 2 activities, say Activity A and Activity B. In Activity A, I have an ImageView
.
Now, I want to change from Activity A to Activity B by clicking into ImageView
. I try to do this, but all of them are false. How can I do that?
Upvotes: 0
Views: 1269
Reputation: 220
You can use this two method
Method1:
Use like this code:
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MyFirstActivity.this, MySecondActivity.class));
}
});
Method2:
imageView.setOnClickListener(this);
And implements in your class like this
Class MyFirstActivity implements View.onClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
//... insert you imageview
}
@Override
private void onClick(View v) {
}
}
Upvotes: 2
Reputation: 9408
If the id of the Imageview in Activity A is "imageView".
Intent class is used to set the current activity and next activity.
Intent takes the 1st parameter as the current activity and takes the 2nd parameter as the next activity.
method startActivity starts the activity which takes the parameter of the intent object.
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// start activity code...
startActivity(new Intent(ActivityA.this,ActivityB.class));
}
});
Upvotes: 0
Reputation: 33438
Here is a straight forward documentation detailing how how to start another activity using click events.
Page on Android developer portal
Please try looking up documentation before asking.
Upvotes: 0
Reputation: 574
ImageView.setOnClickListener(this); And in onClick function Write Intent intent = new Intent(this, SybActivity.class); StartActivity(intent);
Upvotes: 0
Reputation: 6857
Simply set clickListener
on the imageView
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// start activity code...
startActivity(new Intent(CurrentActivity.this, SecondActivity.class));
}
});
Upvotes: 0