0% found this document useful (0 votes)
96 views9 pages

Android EditText for Password Input

The document shows code for an Android application that accepts username and password from the user. It contains XML layout code to display textviews and edittexts for inputting username and password. It also contains Java code to get the input values and display a toast message on button click.
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)
96 views9 pages

Android EditText for Password Input

The document shows code for an Android application that accepts username and password from the user. It contains XML layout code to display textviews and edittexts for inputting username and password. It also contains Java code to get the input values and display a toast message on button click.
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

1.

Write a program to accept username and password from the end user using TextView
and EditText.

Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F2D7"
tools:context=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="250dp"
android:width="120dp"
android:gravity="center"
android:text="Username:"
android:textSize="24dp"

/>

<TextView
android:id="@+id/Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="350dp"
android:width="120dp"
android:gravity="center"
android:text="Password:"
android:textSize="24dp" />

<EditText
android:id="@+id/User_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:layout_marginTop="240dp"
android:width="200dp"></EditText>

<EditText
android:id="@+id/Pass_word"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:layout_marginTop="340dp"
android:inputType="textPassword"
android:width="200dp"></EditText>

<Button
android:id="@+id/Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="450dp"
android:width="200dp"
android:height="60dp"
android:text="Submit"
android:textSize="24dp"></Button>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="650dp"
android:width="400dp"
android:gravity="center"
android:text="Developed By Prathmesh Pote"
android:textSize="24dp" />
</RelativeLayout>
</[Link]>
[Link]

package [Link].exp_7_1;

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

public class MainActivity extends AppCompatActivity {


EditText User_name , Pass_word;
TextView UserName, Password;
String uname, pass;
Button submit;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
submit = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
UserName = findViewById([Link].User_name);
Password = findViewById([Link].Pass_word);
uname = [Link]().toString().trim();
pass = [Link]().toString().trim();
[Link]([Link], "UserName:" + uname,
Toast.LENGTH_LONG).show();
[Link]([Link], "Login Successful",
Toast.LENGTH_SHORT).show();
}
});
}
}
Output:-
[Link] a program to accept and display personal information of the student.

Activity_Main.xml

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


<[Link]
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="[Link]
android:padding="10dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:minHeight="48dp"
android:text="Exp 7_2 Accept Student Information"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.567"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.112" />

<TextView
android:id="@+id/textViewUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name:"
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@id/name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<EditText
android:id="@+id/editTextUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:hint="Enter your name here"
app:layout_constraintTop_toBottomOf="@+id/textViewUser"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textViewPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enrollment:"
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@+id/editTextUser"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<EditText
android:id="@+id/editpass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:hint="Enter your enrollment here"
app:layout_constraintTop_toBottomOf="@+id/textViewPass"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<Button
android:id="@+id/sub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
app:layout_constraintTop_toBottomOf="@+id/editpass"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
</Button>
<TextView
android:id="@+id/disname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@+id/sub"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<TextView
android:id="@+id/disenroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@+id/disname"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:minHeight="48dp"
android:text="Developed by Prathmesh Pote(28)"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.869" />

</[Link]>
[Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText Name,Age;
String name,age;
TextView Display_Name,Display_Age;
Button display;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
display=findViewById([Link]);
[Link](v -> go());
}
public void go()
{
Name=findViewById([Link]);
Age=findViewById([Link]);

name=[Link]().toString().trim();
age=[Link]().toString().trim();

Display_Name=findViewById([Link]);
Display_Age=findViewById([Link]);

Display_Name.setVisibility([Link]);
Display_Name.setText("Name:"+name);

Display_Age.setVisibility([Link]);
Display_Age.setText("Enrollment:"+age);

}
}
Output:-

You might also like