Practical No 7

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Practical No 7

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.

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
android:inputType="text"
/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
/>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click Me!"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
/>

</LinearLayout>
MainActivity.java

package com.example.q1;

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;

public class MainActivity extends AppCompatActivity {


TextView tv1,tv2;
Button click_me;
EditText usr,pass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usr = findViewById(R.id.username);
pass = findViewById(R.id.password);
tv1 = findViewById(R.id.textView);
tv2 = findViewById(R.id.textView2);
click_me = findViewById(R.id.btn);
click_me.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String usr_name = usr.getText().toString();
String password = pass.getText().toString();
tv1.setText(usr_name);
tv2.setText(password);
}
});

Output:

You might also like