Nothing Special   »   [go: up one dir, main page]

Prog TextView EditTextView

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

activity_main.

xml

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


<RelativeLayout
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign In"
android:id="@+id/t1"
android:padding="20dp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter username"
android:id="@+id/uname"
android:layout_below="@id/t1"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:id="@+id/upass"
android:layout_below="@+id/uname"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/submitBtn"
android:hint="Submit"
android:layout_below="@+id/upass"
/>
</RelativeLayout>

MainActivity.java

package in.edu.vpt.texteditdemo;
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 uname, upass;


Button submit;
String defname="prasad"; String defpass="prasad123";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uname=(EditText)findViewById(R.id.uname);
upass=(EditText)findViewById(R.id.upass);
submit=(Button)findViewById(R.id.submitBtn);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(uname.getText().toString().equals(defname) &&
upass.getText().toString().equals(defpass)){
Toast.makeText(MainActivity.this,"Login
Successful",Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(MainActivity.this,"Login
Unsuccessful, invalid credentials",Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output

You might also like