0% found this document useful (0 votes)
6 views5 pages

FA21-BCS-097(LAB # 03)

The document contains an assignment from Muneeb Ahmad Bhatti, a student at COMSATS University Islamabad, detailing a login and to-do list application in Android. The code includes a LoginActivity that verifies hardcoded credentials and a ToDoActivity that displays a list of sample tasks. The assignment is part of the Computer Science course 'MAD'.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

FA21-BCS-097(LAB # 03)

The document contains an assignment from Muneeb Ahmad Bhatti, a student at COMSATS University Islamabad, detailing a login and to-do list application in Android. The code includes a LoginActivity that verifies hardcoded credentials and a ToDoActivity that displays a list of sample tasks. The assignment is part of the Computer Science course 'MAD'.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMSATS UNIVERSITY ISLAMABAD

ASSIGNMENT # 03

 NAME Muneeb Ahmad


Bhatti
 CLASS BCS 6B
 REGISTRATON FA21-BCS-097
NUMBER
 DEPARTMENT COMPUTER SCIENCE
 COURSE MAD
Code

Login Activity:
package com.example.todoapp;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

private EditText usernameField, passwordField;


private Button loginButton;

// Hardcoded username and password


private final String VALID_USERNAME = "Bullah";
private final String VALID_PASSWORD = "hellopy";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

usernameField = findViewById(R.id.username);
passwordField = findViewById(R.id.password);
loginButton = findViewById(R.id.loginButton);

loginButton.setOnClickListener(v -> {
String enteredUsername = usernameField.getText().toString();
String enteredPassword = passwordField.getText().toString();

if (enteredUsername.equals(VALID_USERNAME) &&
enteredPassword.equals(VALID_PASSWORD)) {
// On successful login, navigate to the TodoActivity
Intent intent = new Intent(LoginActivity.this,
ToDoActivity.class);
startActivity(intent);
} else {
Toast.makeText(LoginActivity.this, "Invalid credentials!",
Toast.LENGTH_SHORT).show();
}
});
}
}
To Do List:
package com.example.todoapp;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.Arrays;

public class ToDoActivity extends AppCompatActivity {

private TextView welcomeText;


private ListView todoListView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todo);

welcomeText = findViewById(R.id.welcomeText);
todoListView = findViewById(R.id.todoListView);

// Set the welcome text


welcomeText.setText("Welcome to your To-Do List!");

// Sample tasks
ArrayList<String> tasks = new ArrayList<>(Arrays.asList(
"Get ready for university",
"Reach there before class",
"Leave the university after hours of sufferings",
"Do not die there (optional)",
"Eat and then sleep after reaching home"
));

// Set up the adapter to display tasks


ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, tasks);
todoListView.setAdapter(adapter);
}
}
Screenshots

You might also like