Practical NO.
07
Aim:Develop a program to implement Text iew and Edit Text.
XML CODE:
<?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:orientation="vertical"
android:padding="16dp">
<!-- TextView to display text -->
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your name:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="50dp"/>
<!-- EditText for user input -->
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="name"
android:inputType="textPersonName" />
<TextView
android:id="@+id/phonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Phone Number:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="50dp"/>
<!-- EditText for user input -->
<EditText
android:id="@+id/pnumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="number"
android:inputType="textPhonetic" />
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Address:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="50dp"/>
<!-- EditText for user input -->
<EditText
android:id="@+id/add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="address"
android:inputType="text" />
</LinearLayout>
JAVA CODE
package com.example.roshanidaf;
import android.os.Bundle;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get references to the views
TextView textView = findViewById(R.id.textView);
EditText editText = findViewById(R.id.editText);
// Set a text change listener on the EditText
editText.addTextChangedListener(new android.text.TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
textView.setText("Entered: " + s.toString());
}
@Override
public void afterTextChanged(android.text.Editable s) {}
});
}
}
OUTPUT:
Marks Obtained Dated signature of
Teacher
Process Related Product Related Total (25)
(10) (15)
Practical No. 08
Aim :- Develop a program to implement Button, Image Button and Toggle Button.
Program Code:
XML CODE
<?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:orientation="vertical"
android:padding="16dp">
<!-- TextView and EditText for Name -->
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your name:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textPersonName" />
<!-- TextView and EditText for Phone Number -->
<TextView
android:id="@+id/phonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Phone Number:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/pnumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Number"
android:inputType="phone" />
<!-- TextView and EditText for Address -->
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Address:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:inputType="text" />
<!-- Button -->
<Button
android:id="@+id/submitButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="30dp" />
<!-- ImageButton (You can replace the placeholder with your own image) -->
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:src="@android:drawable/ic_menu_camera"
android:contentDescription="Camera Button"/>
<!-- ToggleButton -->
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="ON"
android:textOff="OFF"
android:layout_marginTop="20dp"/>
</LinearLayout>
OUTPUT:
Marks Obtained Dated signature of
Teacher
Process Related Product Related Total (25)
(10) (15)
Practical No. 09
Aim :- Develop a program to implement Login window using above UI.
Program Code:
XML CODE
<?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:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<!-- Login Image -->
<ImageView
android:id="@+id/loginImageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/login"
android:contentDescription="Login Image"
android:layout_marginBottom="20dp"/>
<!-- TextView and EditText for Username -->
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Username:"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="textPersonName"
android:minHeight="48dp" />
<!-- TextView and EditText for Password -->
<TextView
android:id="@+id/textViewPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Password:"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:minHeight="48dp" />
<!-- Login Button -->
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="30dp" />
</LinearLayout>
JAVA CODE:
package com.example.roshanidaf;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText editTextUsername, editTextPassword;
private Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI components
editTextUsername = findViewById(R.id.editTextUsername);
editTextPassword = findViewById(R.id.editTextPassword);
loginButton = findViewById(R.id.loginButton);
// Handle Login Button Click
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = editTextUsername.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
// Check if username and password are correct (Hardcoded for now)
if (username.equals("admin") && password.equals("1234")) {
Toast.makeText(MainActivity.this, "Login Successful!",
Toast.LENGTH_SHORT).show();
// Navigate to another screen (e.g., HomeActivity) if needed
} else {
Toast.makeText(MainActivity.this, "Invalid Username or Password!",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
OUTPUT:
Marks Obtained Dated signature of
Teacher
Process Related Product Related Total (25)
(10) (15)
Practical No. 10
Aim :- Develop a program to implement Checkbox.
Program Code:
XML CODE
<?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:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<!-- Login Image -->
<ImageView
android:id="@+id/loginImageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/login"
android:contentDescription="Login Image"
android:layout_marginBottom="20dp"/>
<!-- TextView and EditText for Username -->
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Username:"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="textPersonName"
android:minHeight="48dp" />
<!-- TextView and EditText for Password -->
<TextView
android:id="@+id/textViewPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your Password:"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:minHeight="48dp" />
<!-- CheckBox for Remember Me -->
<CheckBox
android:id="@+id/checkBoxRememberMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember Me"
android:textSize="18sp"
android:layout_marginTop="15dp"/>
<!-- Login Button -->
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="30dp" />
</LinearLayout>
OUTPUT:
Marks Obtained Dated signature of
Teacher
Process Related Product Related Total (25)
(10) (15)