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

Practical 7

The document provides two practical exercises for developing Android applications using TextView and EditText components. The first exercise involves creating a login interface with username and password fields, while the second focuses on gathering student information such as name, age, gender, address, phone number, and email. Both exercises include XML layout definitions and Java code for handling user input and displaying results.

Uploaded by

jvaishnavi2502
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 views3 pages

Practical 7

The document provides two practical exercises for developing Android applications using TextView and EditText components. The first exercise involves creating a login interface with username and password fields, while the second focuses on gathering student information such as name, age, gender, address, phone number, and email. Both exercises include XML layout definitions and Java code for handling user input and displaying results.

Uploaded by

jvaishnavi2502
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/ 3

Practical 7:- Develop a program to implement TextView and EditText

Q1.

<?xml version="1.0" encoding="utf-8"?> package com.example.college;


<LinearLayout import android.os.Bundle;
import android.view.View;
xmlns:android="http://schemas.android.com/apk/res/an
2 import android.widget.Button;
droid" import android.widget.EditText;
android:layout_width="match_parent" import android.widget.Toast;
android:layout_height="match_parent"
android:orientation="vertical"> import androidx.activity.EdgeToEdge;
<TextView import androidx.appcompat.app.AppCompatActivity;
android:layout_height="wrap_content" import androidx.core.graphics.Insets;
android:layout_width="wrap_content" import androidx.core.view.ViewCompat;
android:text="User Name" import androidx.core.view.WindowInsetsCompat;
android:textStyle="bold" public class practical7 extends AppCompatActivity
android:layout_marginTop="30dp" {
android:textSize="30dp"> public EditText username,password;
</TextView> public Button btn;
<EditText @Override
android:id="@+id/user" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="50dp" super.onCreate(savedInstanceState);
android:layout_width="match_parent" setContentView(R.layout.activity_practical7);
android:layout_marginStart="10dp" username=findViewById(R.id.user);
android:layout_marginEnd="10dp" password=findViewById(R.id.pass);
android:hint="enter username"> btn=findViewById(R.id.btn);
</EditText> btn.setOnClickListener(new View.OnClickListener() {
<TextView @Override
android:layout_height="wrap_content" public void onClick(View v) {
android:layout_width="wrap_content" String user=username.getText().toString();
android:text="Password" String pass=password.getText().toString();
android:textStyle="bold" if(user.isEmpty()||pass.isEmpty())
android:layout_marginTop="20dp" {
android:textSize="30dp"> Toast.makeText(practical7.this,"Please enter
</TextView> username and password",Toast.LENGTH_LONG).show();
<EditText }
android:id="@+id/pass" else
android:layout_height="50dp" {
android:layout_width="match_parent" Toast.makeText(practical7.this,"Username =
android:layout_marginStart="10dp" "+user+"Password = "+pass,Toast.LENGTH_LONG).show();
android:layout_marginEnd="10dp" }
android:hint="enter password" }
android:inputType="textPassword"> });
</EditText> }
<Button }
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:text="Submit"
android:id="@+id/btn"
/>
</LinearLayout>
Q2

<?xml version="1.0" encoding="utf-8"?> package com.example.college;


<LinearLayout import android.os.Bundle;
xmlns:android="http://schemas.android.com/apk/res/a import android.view.View;
ndroid" import android.widget.Button;
android:layout_width="match_parent" import android.widget.EditText;
android:layout_height="match_parent" import android.widget.TextView;
android:orientation="vertical" import androidx.activity.EdgeToEdge;
android:padding="16dp"> import androidx.appcompat.app.AppCompatActivity;
<TextView import androidx.core.graphics.Insets;
android:layout_width="match_parent" import androidx.core.view.ViewCompat;
android:layout_height="wrap_content" import androidx.core.view.WindowInsetsCompat;
android:text="Enter Student Information" public class practical7ii extends AppCompatActivity{
android:textSize="30sp" private EditText nameEditText;
android:textStyle="bold" /> private EditText ageEditText;
<EditText private EditText genderEditText;
android:id="@+id/name_edit_text" private EditText addressEditText;
android:layout_width="match_parent" private EditText phoneNumberEditText;
android:layout_height="wrap_content" private EditText emailEditText;
android:hint="Enter student name" private Button submitButton;
android:inputType="text" /> private TextView displayTextView;
<EditText @Override
android:id="@+id/age_edit_text" protected void onCreate(Bundle savedInstanceState) {
android:layout_width="match_parent" super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_practical7ii);
android:hint="Enter student age" nameEditText = findViewById(R.id.name_edit_text);
android:inputType="number" /> ageEditText = findViewById(R.id.age_edit_text);
<EditText genderEditText = findViewById(R.id.gender_edit_text);
android:id="@+id/gender_edit_text" addressEditText = findViewById(R.id.address_edit_text);
android:layout_width="match_parent" phoneNumberEditText =
android:layout_height="wrap_content" findViewById(R.id.phone_number_edit_text);
android:hint="Enter student gender" emailEditText = findViewById(R.id.email_edit_text);
android:inputType="text" /> submitButton = findViewById(R.id.submit_button);
<EditText displayTextView = findViewById(R.id.display_text_view);
android:id="@+id/address_edit_text" submitButton.setOnClickListener(new View.OnClickListener()
android:layout_width="match_parent" {
android:layout_height="wrap_content" @Override
android:hint="Enter student address" public void onClick(View v) {
android:inputType="textPostalAddress" /> String name = nameEditText.getText().toString();
<EditText String age = ageEditText.getText().toString();
android:id="@+id/phone_number_edit_text" String gender = genderEditText.getText().toString();
android:layout_width="match_parent" String address = addressEditText.getText().toString();
android:layout_height="wrap_content" String phoneNumber =
android:hint="Enter student phone number" phoneNumberEditText.getText().toString();
android:inputType="phone" /> String email = emailEditText.getText().toString();
<EditText String displayText = "Name: " + name + "\nAge: " + age +
android:id="@+id/email_edit_text" "\nGender: " + gender + "\nAddress: " + address + "\nPhone
android:layout_width="match_parent" Number: " + phoneNumber + "\nEmail: " + email;
android:layout_height="wrap_content" displayTextView.setText(displayText);
android:hint="Enter student email" }
android:inputType="textEmailAddress" /> }); }}
<Button
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:text="Submit" />
<TextView
android:id="@+id/display_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>

Output-

You might also like