0% found this document useful (0 votes)
9 views2 pages

Prcatical No 10

Uploaded by

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

Prcatical No 10

Uploaded by

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

1.

Write a program to create log in form


Program Code:-
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="87dp"
android:ems="10"
android:inputType="textPersonName" />

<EditText
android:id="@+id/editText1"
android:layout_width="422dp"
android:layout_height="82dp"
android:ems="10"
android:inputType="textPersonName" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Log In" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final EditText e1=(EditText)findViewById(R.id.editText);


final EditText e2=(EditText)findViewById(R.id.editText1);
final Button b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(e1.getText().toString().equals("admin") &&
e2.getText().toString().equals("admin"))
{
Toast.makeText(getApplicationContext(),"Login
Successful !!!!!",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(),"Invalid User
Name or Password ",Toast.LENGTH_LONG).show();
}
}
});

}
}

Output:-

You might also like