Practical No 07

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practical No: 7

 Develop a program to implement Text View and Edit View.


 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<TableLayout 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"
android:padding="50dp"
android:background="#3EB489"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="25dp"
android:text="Login Page" />

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">

<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="UserName :" />

<EditText
android:id="@+id/user"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="abc@gmail.com" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">

<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Password :" />

<EditText
android:id="@+id/pass"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="1234"
android:inputType="textPassword"/>
</TableRow>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="172dp"
android:text="Login" />
</TableLayout>

 MainActivity.java

package com.example.pr7;

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 {


EditText user,pass;
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b= findViewById(R.id.btn1);
user = findViewById(R.id.user);
pass = findViewById(R.id.pass);

b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(user.getText().toString().equals("vaibhav") &
pass.getText().toString().equals("1234"))
{
Toast.makeText( getApplicationContext(),"Login
Sucessful",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText( getApplicationContext(),"Login
UnSucessful",Toast.LENGTH_SHORT).show();
}
}
});
}
}
 Output:

You might also like