Android Beginner Project with Database Connectivity & Layout Design

Jul 21, 2024

Android Beginner Project with Database Connectivity & Layout Design 📱

Introduction

  • Lecture by Nilesh Borate from Village Technology
  • Overview of an Android project with database connectivity, attractive layout design, etc.

Setting Up the Project

  • **Creating a New Project: **
    1. Go to File > New > New Project
    2. Select Empty Activity and click on Next
    3. Give your application a name, package name, save location, and choose Java as the programming language
    4. Minimum SDK version: API 21 (Android 5.0)
    5. Click on Finish
  • **Project Structure: **
    • MainActivity.java and activity_main.xml created
    • Project structure visible in the IDE
  • Creating Emulator:
    1. Go to AVD Manager
    2. Click Create Virtual Device, select device (e.g., Pixel 2), set screen size, resolution, density
    3. Choose Android version (API 30 - Android 11.0)
    4. Click Next and Finish
  • Running the App:
    • Choose emulator from dropdown and click Run App
    • Default message “Hello World” displayed on emulator

Layout Design

  • activity_main.xml:
    • Constraint layout used for design through drag-and-drop
    • Default view: TextView with “Hello World” message
    • Design sections: Code section, Split section, Design section
  • **Adding Layout Elements: **
    • Drag and drop background images, icons, layouts to drawable folder
    • Design various UI components like TextView (e.g., “Hello World”)
  • **Creating Login Activity: **
    • New Empty Activity: LoginActivity.java and activity_login.xml
    • Set background image, add TextView, EditText (username, password), Button (login), and TextView (new user)
    • Define properties via attributes or code, such as text size, style, color, padding, and input type
    • Use constraints to position elements in the layout

Adding Material and Resources

  • **Adding Drawable Resources: **
    • Copy images, icons, shapes into drawable folder
    • Define colors in colors.xml within the values folder and reference them in your layout
  • **Changing Activity Backgrounds: **
    • Set background properties for activities from drawable resources

Handling User Interactions

  • **Login Button: **
    • Implement setOnClickListener() for login button to validate inputs
    • Display toast messages for login success or input validation (e.g., empty fields)
  • **Navigating to Registration Activity: **
    • Using Intent to navigate on clicking “Register”
    • Create RegistrationActivity.java and activity_registration.xml
    • Similar layout design to login activity, add more fields (e.g., confirm password, email)
    • Validate inputs and create user in database

Database Setup and Operations

  • **Creating Database Helper Class: **
    • Create Database.java extending SQLiteOpenHelper
    • Implement onCreate() and onUpgrade() methods for creating and updating tables
    • Define tables (e.g., users table) and write database queries (e.g., insert user, check login)
  • **Implementing Registration and Login: **
    • Register function to insert user details into database
    • Login function to validate user credentials and manage sessions with SharedPreferences

Displaying Data in Activities

  • **Using Intents: **
    • Passing data between activities using Intent extras
  • **Updating Layouts Dynamically: **
    • Using ArrayAdapter and ListView for displaying dynamic content
    • Example: Showing list of doctors in FindDoctorActivity

Advanced UI Components

  • **CardView and GridLayout: **
    • Using CardView inside GridLayout to display interactive items (e.g., health articles)
    • Example: Design HomeActivity with multiple card views
  • **RecyclerView Implementation: **
    • For displaying extensive lists like health articles or tests with consistent layout

Extra Functionalities

  • **Health Articles Section: **
    • Displaying a list of health articles with images and descriptions
    • Navigating to detailed article view
  • **Session Management & Shared Preferences: **
    • Storing user session details in SharedPreferences
    • Fetching user data across activities

Complete Flow

  • Register user, login, and navigate through activities (e.g., list doctors, book appointments)
  • Insert and retrieve data from the database
  • Display toasts and handle user inputs in real time
  • Comprehensive error handling and UI feedback to users

Summary

  • Create a basic Android app with user authentication, database connectivity, and dynamic UI updates
  • Use various Android components and structures such as activities, intents, SQLite database, SharedPreferences, and UI layouts
  • Employ effective error handling and user interaction feedback

**Note: **

  • This is a basic starter project for Android beginners to understand fundamental concepts and implement commonly used features in an app