FA21-BCS-097(LAB # 03)
FA21-BCS-097(LAB # 03)
ASSIGNMENT # 03
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;
@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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todo);
welcomeText = findViewById(R.id.welcomeText);
todoListView = findViewById(R.id.todoListView);
// 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"
));