Practical 7 PDF
Practical 7 PDF
1. Write a program to accept username and password from the end user using Text View and
Edit Text.
Xml code:
android:inputType="textPassword"
/> </FrameLayout>
Java code:
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:
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);
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: