Practical No 7
Practical No 7
Practical No. 7: Develop a program to implement Text View and Edit Text
I. Practical Significance
In this practical, UI controls in android like Text view and edit view are studied.
Wherein the UI controls can be developed, used and placed on the screen using
different layout managers as per the problem statement requirements.
1. Text View:
In Android, Text View displays text to the user and optionally allows them to edit it
programmatically. Text View is a complete text editor, however basic class is configured to
not allow editing but we can edit it. View is the parent class of Text View Being a subclass of
view the text view component can be used in your app’s.
GUI inside a View Group, or as the content view of an activity. We can create a Text View
instance by declaring it inside a layout (XML file) or by instantiating it programmatically(Java
Class).
2. Edit Text:
In Android, Edit Text is a standard entry widget in android apps. It is an overlay over Text
View that configures itself to be editable. Edit Text is a subclass of Text View with text
editing operations. Often use Edit Text in our applications in order to provide an input or
text field, especially in forms. The simplest example of Edit Text is Login or Sign-in form.
Text Fields in Android Studio are basically Edit Text.
Note: An Edit Text is simply a thin extension of a Text View. An Edit Text inherits all the
properties of a Text View.
b. Visible
c. Foreground
d. Background
2. What is the name of the folder that contains the R.java file?
a. src
b. res
c. bin
d. gen
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to accept username and password from the end user using Text View
and Edit Text.
2. Write a program to accept and display personal information of the student.
1.
//MainActivity.java
package com.jamiapolytechnic.experiment71;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (name.getText().toString().isEmpty() ||
password.getText().toString().isEmpty()) {
result.setText("Please Fill All the Details");
}
}
});
}
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email or Phone"
android:textSize="15sp"/>
<EditText
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="25"
android:hint="Enter Email ID or Phone No." />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="15sp"/>
<EditText
android:id="@+id/txtPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="25"
android:hint="Enter Password" />
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textSize="15sp"
android:textStyle="normal|bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
2.
//MainActivity.java
package com.jamiapolytechnic.experiment72;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
}
});
}
}
//========================================================================
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40dp"
android:orientation="vertical" android:id="@+id/linearlayout" >
<EditText
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="Name"
android:inputType="text"
android:selectAllOnFocus="true" />
<EditText
android:id="@+id/txtPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password 0 to 9"
android:inputType="numberPassword" />
<EditText
android:id="@+id/txtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:ems="10"
android:hint="Date of Birth"
android:inputType="date" />
<EditText
android:id="@+id/txtPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
android:textColorHint="#FE8DAB"/>
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:textSize="16sp"
android:textStyle="normal|bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultView"
android:layout_marginTop="25dp"
android:textSize="15dp"/>
</LinearLayout>
1
2
3
4
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)