0% found this document useful (0 votes)
10 views1 page

Important Codes

The document is a Java code snippet for an Android application that defines the MainActivity class. It initializes a button from the layout and sets an OnClickListener to open a new page when the button is clicked. The openpage method creates an Intent to start another activity called 'page'.

Uploaded by

afabaangang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Important Codes

The document is a Java code snippet for an Android application that defines the MainActivity class. It initializes a button from the layout and sets an OnClickListener to open a new page when the button is clicked. The openpage method creates an Intent to start another activity called 'page'.

Uploaded by

afabaangang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package com.example.

coronahelpline;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

private Button button; //

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
*Each activity must have a corresponding layout XML file
*/
setContentView(R.layout.activity_main);// activity_main is corresponding
XML file

/*
* Initializing button XML button id. findViewById is a method which
* helps to initialize with particular id. btn_go_to_another_activity is
* a button name which I have given in XML file
*/
button = (Button) findViewById(R.id.button);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
openpage();

}
});
}
public void openpage(){
Intent intent=new Intent(this,page.class);
startActivity(intent);
}

You might also like