I need to use a .java file to perform actions for a .xml layout. I have used this layout for a dialog box. I have linked the .java file to that layout but it doesn't seem to work at all.
This is the MainActivity
package com.example.ayush.projectfive;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button btn;
AlertDialog.Builder alrt;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn = (Button) findViewById(R.id.button);
    alrt = new AlertDialog.Builder(MainActivity.this);
    alrt.setIcon(R.mipmap.ic_launcher);
    alrt.setTitle("Login");
    alrt.setCancelable(false);
    alrt.setView(R.layout.mylayout);
    alrt.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    alrt.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alrt.show();
            Intent i = new Intent(MainActivity.this,Second.class);
            startActivity(i);
        }
    });
}
}
This is the activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ayush.projectfive.MainActivity">
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="EXIT"
    android:id="@+id/button"
    android:layout_gravity="center_horizontal" />
This is the dialog box layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="LOGIN"
    android:id="@+id/textView"
    android:layout_gravity="center_horizontal" />
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Username"
    android:layout_marginTop="20dp"
    android:id="@+id/editText" />
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password"
    android:layout_marginTop="15dp"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/editText2" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Login"
    android:layout_marginTop="20dp"
    android:id="@+id/button3" />
This is the .java file I'd like to link with.
package com.example.ayush.projectfive;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Second extends AppCompatActivity{
EditText et, et2;
Button btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mylayout);
    et = (EditText) findViewById(R.id.editText);
    et2 = (EditText) findViewById(R.id.editText2);
    btn2 = (Button) findViewById(R.id.button3);
    btn2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String s1 = et.getText().toString();
            String s2 = et.getText().toString();
            if(s1.equals(s2)){
                Toast.makeText(Second.this, "Login Successful",      Toast.LENGTH_SHORT).show();
                Intent i = new Intent(Second.this,Third.class);
                startActivity(i);
            }
            else{
            }
        }
    });
}
}
 
     
     
    