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

Practical 8 Code With Output

The document contains an Android application code with a main activity that allows users to input their username, password, and select their gender. Upon clicking the login button, it validates the inputs and displays a success message with the entered username and selected gender. The layout is defined in XML, featuring EditText fields for username and password, a RadioGroup for gender selection, and a Button to submit the form.

Uploaded by

kondvilkarvedant
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)
2 views3 pages

Practical 8 Code With Output

The document contains an Android application code with a main activity that allows users to input their username, password, and select their gender. Upon clicking the login button, it validates the inputs and displays a success message with the entered username and selected gender. The layout is defined in XML, featuring EditText fields for username and password, a RadioGroup for gender selection, and a Button to submit the form.

Uploaded by

kondvilkarvedant
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

Ac vitymain.

java
package [Link].prac8;

import [Link];
import [Link];
import [Link].*;

import [Link];

public class MainActivity extends AppCompatActivity {

EditText etUsername, etPassword;


RadioGroup radioGroupGender;
Button btnLogin;
TextView tvResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etUsername = findViewById([Link]);
etPassword = findViewById([Link]);
radioGroupGender = findViewById([Link]);
btnLogin = findViewById([Link]);
tvResult = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {

String username = [Link]().toString().trim();


String password = [Link]().toString().trim();

if ([Link]()) {
[Link]("Username required");
return;
}

if ([Link]()) {
[Link]("Password required");
return;
}

int selectedGenderId =
[Link]();

if (selectedGenderId == -1) {
[Link]([Link],
"Select gender", Toast.LENGTH_SHORT).show();
return;
}

RadioButton selectedGender =
findViewById(selectedGenderId);

String gender = [Link]().toString();

[Link](
"Login Successful\nUsername: " + username +
"\nGender: " + gender
);
}
});
}
}

ac [Link]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />

<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rbMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

<RadioButton
android:id="@+id/rbFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>

<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />

<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:paddingTop="10dp" />

</LinearLayout>

You might also like