Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
476 views

Practical 7 PDF

The document describes a program to accept and display personal information of a student using TextView and EditText widgets in Android. It includes XML code to define the layout containing TextViews and EditTexts to accept name, phone number, age and blood group. The Java code will find the views by ID and display the input information on button click.

Uploaded by

Ajinkya Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
476 views

Practical 7 PDF

The document describes a program to accept and display personal information of a student using TextView and EditText widgets in Android. It includes XML code to define the layout containing TextViews and EditTexts to accept name, phone number, age and blood group. The Java code will find the views by ID and display the input information on button click.

Uploaded by

Ajinkya Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical No. 7 : Develop a program to implement Text View and Edit Text.

Name: Ajinkya P. Patil Class: TYCM-II Roll No: 39

1. 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- android:layout_height="wrap_conten


8"?> t"
<FrameLayout android:hint="User name"
xmlns:android="http://schemas.andr android:textSize="17dp"
oid.com/apk/res/android"
android:layout_gravity="right |
xmlns:app="http://schemas.android. top"
com/apk/res-auto"
app:layout_constraintBottom_toBott
xmlns:tools="http://schemas.androi omOf="parent"
d.com/tools"
app:layout_constraintEnd_toEndOf="
android:layout_width="match_parent parent"
"
app:layout_constraintStart_toStart
android:layout_height="match_paren Of="parent"
t"
tools:context=".MainActivity"> app:layout_constraintTop_toTopOf="
parent" />
<TextView
android:id="@+id/t1" <TextView
android:id="@+id/t2"
android:layout_width="wrap_content
" android:layout_width="wrap_content
"
android:layout_height="wrap_conten
t" android:layout_height="wrap_conten
android:text="Enter User t"
name: " android:text="Enter
android:textSize="17dp" Paswword name: "
android:textSize="17dp"
app:layout_constraintBottom_toBott
omOf="parent" android:layout_gravity="left |
center"
app:layout_constraintEnd_toEndOf="
parent" app:layout_constraintBottom_toBott
omOf="parent"
app:layout_constraintStart_toStart
Of="parent" app:layout_constraintEnd_toEndOf="
parent"
app:layout_constraintTop_toTopOf="
parent" /> app:layout_constraintStart_toStart
Of="parent"
<EditText
android:id="@+id/e1" app:layout_constraintTop_toTopOf="
parent" />
android:layout_width="wrap_content
" <EditText
android:id="@+id/e2"
android:hint="Password" <Button
android:id="@+id/b1"
android:layout_width="wrap_content
" android:layout_gravity="center |
bottom"
android:layout_height="wrap_conten
t" android:layout_width="wrap_content
"
android:layout_gravity="right |
center" android:layout_height="wrap_conten
android:textSize="17dp" t"
android:ems="10" android:text="Button" />

android:inputType="textPassword"
/> </FrameLayout>

Java code:

package com.example.practical7; Button b1 = (Button)


findViewById(R.id.b1);
import
androidx.appcompat.app.AppCompatAc b1.setOnClickListener(new
tivity; View.OnClickListener() {
@Override
import android.os.Bundle; public void
import android.view.View; onClick(View v) {
import android.widget.Button;
import android.widget.EditText; if(e2.getText().toString().equals(
import android.widget.TextView; "abc") &&
import android.widget.Toast; e1.getText().toString().equals("ef
g"))
public class MainActivity extends {
AppCompatActivity {
Toast.makeText(getApplicationConte
@Override xt(),"User id and password is
protected void onCreate(Bundle correct",Toast.LENGTH_SHORT).show(
savedInstanceState) { );
}
super.onCreate(savedInstanceState) else
; {

setContentView(R.layout.activity_m Toast.makeText(getApplicationConte
ain); xt(),"Enter valid user id or
TextView t1 = (TextView) password",Toast.LENGTH_SHORT).show
findViewById(R.id.t1); ();
EditText e1 = (EditText) }
findViewById(R.id.e2); }
TextView t2 = (TextView) });
findViewById(R.id.t2); }
EditText e2 = (EditText) }
findViewById(R.id.e1);
Output:
2. Write a program to accept and display personal information of the student.

Xml code:

<?xml version="1.0" encoding="utf- android:hint="Name"


8"?> android:textSize="20dp"
<TableLayout />
xmlns:android="http://schemas.andr </TableRow>
oid.com/apk/res/android"
<TableRow>
xmlns:app="http://schemas.android. <TextView
com/apk/res-auto"
android:layout_width="wrap_content
xmlns:tools="http://schemas.androi "
d.com/tools"
android:layout_height="wrap_conten
android:layout_width="match_parent t"
" android:text="Enter
your phone no: "
android:layout_height="match_paren
t" android:textSize="20dp"
tools:context=".MainActivity">
<TableRow> app:layout_constraintBottom_toBott
<TextView omOf="parent"

app:layout_constraintEnd_toEndOf="
android:layout_width="wrap_content parent"
"
app:layout_constraintStart_toStart
android:layout_height="wrap_conten Of="parent"
t"
android:text="Enter your app:layout_constraintTop_toTopOf="
name : " parent" />
android:textSize="20dp"
<EditText
app:layout_constraintBottom_toBott android:id="@+id/e2"
omOf="parent"
android:layout_width="210dp"
app:layout_constraintEnd_toEndOf="
parent" android:layout_height="wrap_conten
t"
app:layout_constraintStart_toStart
Of="parent" android:layout_marginLeft="40dp"
android:hint="phone
app:layout_constraintTop_toTopOf=" no"
parent" />
android:textSize="20dp"
<EditText />
</TableRow>
android:id="@+id/e1"
<TableRow>
android:layout_width="210dp" <TextView

android:layout_height="wrap_conten android:layout_width="wrap_content
t" "

android:layout_marginLeft="40dp" android:layout_height="wrap_conten
t" android:id="@+id/e4"
android:text="Enter
your age: " android:layout_width="210dp"

android:textSize="20dp" android:layout_height="wrap_conten
t"
app:layout_constraintBottom_toBott
omOf="parent" android:layout_marginLeft="40dp"
android:hint="e.g. O+,
app:layout_constraintEnd_toEndOf=" A-"
parent"
android:textSize="20dp"
app:layout_constraintStart_toStart />
Of="parent" </TableRow>

app:layout_constraintTop_toTopOf=" <TableRow>
parent" />
<TextView
<EditText
android:id="@+id/e3" android:layout_width="wrap_content
"
android:layout_width="match_parent
" android:layout_height="wrap_conten
t"
android:layout_height="wrap_conten android:text="press
t" ther button: "

android:layout_marginLeft="40dp" android:textSize="20dp"
android:hint="age"
app:layout_constraintBottom_toBott
android:textSize="20dp" omOf="parent"
/>
</TableRow> app:layout_constraintEnd_toEndOf="
parent"
<TableRow>
<TextView app:layout_constraintStart_toStart
Of="parent"
android:layout_width="wrap_content
" app:layout_constraintTop_toTopOf="
parent" />
android:layout_height="wrap_conten <Button
t"
android:text="Enter android:id="@+id/b1"
blood group: "
android:text="button"
android:textSize="20dp" />
</TableRow>
app:layout_constraintBottom_toBott
omOf="parent" <TableRow>

app:layout_constraintEnd_toEndOf=" <TextView
parent"
android:layout_width="wrap_content
app:layout_constraintStart_toStart "
Of="parent"
android:layout_height="wrap_conten
app:layout_constraintTop_toTopOf=" t"
parent" />
android:text="Information is : "
<EditText
android:textSize="20dp"
app:layout_constraintBottom_toBott android:layout_height="wrap_conten
omOf="parent" t"
android:text="Phone
app:layout_constraintEnd_toEndOf=" no: "
parent"
android:textSize="20dp"
app:layout_constraintStart_toStart
Of="parent" app:layout_constraintBottom_toBott
omOf="parent"
app:layout_constraintTop_toTopOf="
parent" /> app:layout_constraintEnd_toEndOf="
parent"
</TableRow>
app:layout_constraintStart_toStart
<TableRow> Of="parent"
<TextView
app:layout_constraintTop_toTopOf="
parent" />
android:layout_width="wrap_content
" <TextView
android:id="@+id/t2"
android:layout_height="wrap_conten
t" android:layout_width="match_parent
android:text="Name: " "

android:textSize="20dp" android:layout_height="wrap_conten
t"
app:layout_constraintBottom_toBott
omOf="parent" android:layout_marginLeft="40dp"

app:layout_constraintEnd_toEndOf=" android:textSize="20dp"
parent" />
</TableRow>
app:layout_constraintStart_toStart
Of="parent" <TableRow>
<TextView
app:layout_constraintTop_toTopOf="
parent" />
android:layout_width="wrap_content
<TextView "
android:id="@+id/t1"
android:layout_height="wrap_conten
android:layout_width="match_parent t"
" android:text="Age: "

android:layout_height="wrap_conten android:textSize="20dp"
t"
app:layout_constraintBottom_toBott
android:layout_marginLeft="40dp" omOf="parent"

android:textSize="20dp" app:layout_constraintEnd_toEndOf="
/> parent"
</TableRow>
app:layout_constraintStart_toStart
<TableRow> Of="parent"
<TextView
app:layout_constraintTop_toTopOf="
parent" />
android:layout_width="wrap_content
" <TextView
android:id="@+id/t3"
app:layout_constraintEnd_toEndOf="
android:layout_width="match_parent parent"
"
app:layout_constraintStart_toStart
android:layout_height="wrap_conten Of="parent"
t"
app:layout_constraintTop_toTopOf="
android:layout_marginLeft="40dp" parent" />

android:textSize="20dp" <TextView
/> android:id="@+id/t4"
</TableRow>
android:layout_width="match_parent
<TableRow> "
<TextView
android:layout_height="wrap_conten
t"
android:layout_width="wrap_content
" android:layout_marginLeft="40dp"

android:layout_height="wrap_conten android:textSize="20dp"
t" />
android:text="Blood </TableRow>
group: "

android:textSize="20dp" </TableLayout>

app:layout_constraintBottom_toBott
omOf="parent"

Java Code:

package
com.example.pr7_print_info; setContentView(R.layout.activity_m
ain);
import
androidx.appcompat.app.AppCompatAc EditText e1 =
tivity; findViewById(R.id.e1);
EditText e2 =
import android.os.Bundle; findViewById(R.id.e2);
import android.view.View; EditText e3 =
import android.widget.Button; findViewById(R.id.e3);
import android.widget.EditText; EditText e4 =
import android.widget.TextView; findViewById(R.id.e4);

public class MainActivity extends TextView t1 =


AppCompatActivity { findViewById(R.id.t1);
TextView t2 =
findViewById(R.id.t2);
TextView t3 =
@Override findViewById(R.id.t3);
protected void onCreate(Bundle TextView t4 =
savedInstanceState) { findViewById(R.id.t4);

super.onCreate(savedInstanceState) Button b1 =
; findViewById(R.id.b1);
String i4 =
b1.setOnClickListener(new e4.getText().toString();
View.OnClickListener() {
@Override t1.setText(i1);
public void t2.setText(i2);
onClick(View v) { t3.setText(i3);
String i1 = t4.setText(i4);
e1.getText().toString(); }
String i2 = });
e2.getText().toString();
String i3 = }
e3.getText().toString(); }

Output:

You might also like