I have made one screen with two images and I would like to add a button lower on the page which will navigate to a second page when I click it. Do you know how to code this? I know how to create a button but I don't know how to connect the two screens!
This task is accomplished with the startActivity(); method using Intents.
Intent i = new Intent(FromActivity.this, ToActivity.class);
startActivity(i);
In this case the Intent uses your current Activity as the Context in the first parameter, and the destination Activity in the second parameter.
Make sure that you add your second Activity to the manifest also (it resides in the tag)!
<activity android:name=".ToActivity"
android:label="@string/app_name">
</activity>
To sum it up:
ImageView myImage = (ImageView) findViewById(R.id.image);
myImage.setOnClickListener(new OnClickListener() {
@Override
onClick(View v) {
Intent intent = new Intent(FromActivity.this, ToActivity.class);
startActivity(intent);
}
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With