0% found this document useful (0 votes)
53 views3 pages

Password Retrieval in Login Screen

The document contains code for an Android login activity. The activity_main.xml layout file defines the user interface containing a TextView for the title, EditText fields for the username and password, and a submit Button. The MainActivity class sets up the click listener for the submit button to check credentials and display a toast message with the login result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Password Retrieval in Login Screen

The document contains code for an Android login activity. The activity_main.xml layout file defines the user interface containing a TextView for the title, EditText fields for the username and password, and a submit Button. The MainActivity class sets up the click listener for the submit button to check credentials and display a toast message with the login result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

activity_main.

xml

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


<RelativeLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
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>

[Link]

package [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText uname, upass;


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

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
uname=(EditText)findViewById([Link]);
upass=(EditText)findViewById([Link]);
submit=(Button)findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
if([Link]().toString().equals(defname) &&
[Link]().toString().equals(defpass)){
[Link]([Link],"Login
Successful",Toast.LENGTH_LONG).show();
}
else{
[Link]([Link],"Login
Unsuccessful, invalid credentials",Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output

You might also like