0% found this document useful (0 votes)
16 views7 pages

Practical 7

The document describes two Android programs: 1) a program to accept username and password from text fields, 2) a program to accept and display personal information from text fields like name, age, email.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Practical 7

The document describes two Android programs: 1) a program to accept username and password from text fields, 2) a program to accept and display personal information from text fields like name, age, email.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

MAD CO6I Practical 7

Name: Pranjal Shahane Roll No: 06


Practical: 7

Q. Write a program to accept username and password from the end


user using Text View and Edit Text.
XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/textViewUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username:" />

<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter username"
android:inputType="text" />

<TextView
android:id="@+id/textViewPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password:" />

Gramin Technical & managemnet campus 1


MAD CO6I Practical 7

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter password"
android:inputType="textPassword" />

</LinearLayout>
Java code:
package com.example.myapplication;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Find views by ID
TextView textViewUsername = findViewById(R.id.textViewUsername);
EditText editTextUsername = findViewById(R.id.editTextUsername);
TextView textViewPassword = findViewById(R.id.textViewPassword);
EditText editTextPassword = findViewById(R.id.editTextPassword);
}
}

Gramin Technical & managemnet campus 2


MAD CO6I Practical 7

OUTPUT:

Q. Write a program to accept and display personal information of the


student.
XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/textViewName"
android:layout_width="match_parent"

Gramin Technical & managemnet campus 3


MAD CO6I Practical 7

android:layout_height="wrap_content"
android:text="Name:" />

<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:inputType="text" />

<TextView
android:id="@+id/textViewAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Age:" />

<EditText
android:id="@+id/editTextAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your age"
android:inputType="number" />

<TextView
android:id="@+id/textViewEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email:" />

<EditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:inputType="textEmailAddress" />

<Button

Gramin Technical & managemnet campus 4


MAD CO6I Practical 7

android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Submit" />

<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Student Information:"
android:textStyle="bold" />

</LinearLayout>
Java code:
package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText editTextName, editTextAge, editTextEmail;


TextView textViewResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Gramin Technical & managemnet campus 5


MAD CO6I Practical 7

// Find views by ID
editTextName = findViewById(R.id.editTextName);
editTextAge = findViewById(R.id.editTextAge);
editTextEmail = findViewById(R.id.editTextEmail);
textViewResult = findViewById(R.id.textViewResult);
Button buttonSubmit = findViewById(R.id.buttonSubmit);

// Set OnClickListener for the submit button


buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get the entered information
String name = editTextName.getText().toString();
String age = editTextAge.getText().toString();
String email = editTextEmail.getText().toString();

// Display the information


String info = "Name: " + name + "\n" +
"Age: " + age + "\n" +
"Email: " + email;
textViewResult.setText(info);
}
});
}
}

OUTPUT:

Gramin Technical & managemnet campus 6


MAD CO6I Practical 7

Gramin Technical & managemnet campus 7

You might also like