0% found this document useful (0 votes)
257 views8 pages

Practical 7: User Input in Android

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
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)
257 views8 pages

Practical 7: User Input in Android

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
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
  • Practical No. 7: Task 1 - Text View and Edit Text
  • Practical No. 7: Task 2 - Display Student Information

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="[Link] android:textSize="17dp"
[Link]/apk/res/android"
android:layout_gravity="right |
xmlns:app="[Link] top"
com/apk/res-auto"
app:layout_constraintBottom_toBott
xmlns:tools="[Link] omOf="parent"
[Link]/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 [Link].practical7; Button b1 = (Button)


findViewById([Link].b1);
import
[Link] [Link](new
tivity; [Link]() {
@Override
import [Link]; public void
import [Link]; onClick(View v) {
import [Link];
import [Link]; if([Link]().toString().equals(
import [Link]; "abc") &&
import [Link]; [Link]().toString().equals("ef
g"))
public class MainActivity extends {
AppCompatActivity {
[Link](getApplicationConte
@Override xt(),"User id and password is
protected void onCreate(Bundle correct",Toast.LENGTH_SHORT).show(
savedInstanceState) { );
}
[Link](savedInstanceState) else
; {

setContentView([Link].activity_m [Link](getApplicationConte
ain); xt(),"Enter valid user id or
TextView t1 = (TextView) password",Toast.LENGTH_SHORT).show
findViewById([Link].t1); ();
EditText e1 = (EditText) }
findViewById([Link].e2); }
TextView t2 = (TextView) });
findViewById([Link].t2); }
EditText e2 = (EditText) }
findViewById([Link].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="[Link] </TableRow>
[Link]/apk/res/android"
<TableRow>
xmlns:app="[Link] <TextView
com/apk/res-auto"
android:layout_width="wrap_content
xmlns:tools="[Link] "
[Link]/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
[Link].pr7_print_info; setContentView([Link].activity_m
ain);
import
[Link] EditText e1 =
tivity; findViewById([Link].e1);
EditText e2 =
import [Link]; findViewById([Link].e2);
import [Link]; EditText e3 =
import [Link]; findViewById([Link].e3);
import [Link]; EditText e4 =
import [Link]; findViewById([Link].e4);

public class MainActivity extends TextView t1 =


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

[Link](savedInstanceState) Button b1 =
; findViewById([Link].b1);
String i4 =
[Link](new [Link]().toString();
[Link]() {
@Override [Link](i1);
public void [Link](i2);
onClick(View v) { [Link](i3);
String i1 = [Link](i4);
[Link]().toString(); }
String i2 = });
[Link]().toString();
String i3 = }
[Link]().toString(); }

Output:

Practical No. 7 : Develop a program to implement Text View and Edit Text. 
Name: Ajinkya P. Patil   
 
 
Class: TYCM-II
android:hint="Password" 
        
android:layout_width="wrap_content
" 
        
android:layout_height="wrap_conten
t
Output:
2. Write a program to accept and display personal information of the student. 
 
Xml code:  
 
<?xml version="1.0" encoding="
t" 
            android:text="Enter 
your age:  " 
            
android:textSize="20dp" 
            
app:layout_constraintBo
app:layout_constraintBottom_toBott
omOf="parent" 
            
app:layout_constraintEnd_toEndOf="
parent"
android:id="@+id/t3" 
            
android:layout_width="match_parent
" 
            
android:layout_height="wrap
b1.setOnClickListener(new 
View.OnClickListener() { 
            @Override 
            public void 
onClick(View v

You might also like