<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sanskar Singh</title>
    <description>The latest articles on DEV Community by Sanskar Singh (@sanskar_singh_3e842eec7e6).</description>
    <link>https://dev.to/sanskar_singh_3e842eec7e6</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3054125%2Fffe24c29-08a4-4ea3-aa06-4760032ecf84.png</url>
      <title>DEV Community: Sanskar Singh</title>
      <link>https://dev.to/sanskar_singh_3e842eec7e6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanskar_singh_3e842eec7e6"/>
    <language>en</language>
    <item>
      <title>Log in/Sign up</title>
      <dc:creator>Sanskar Singh</dc:creator>
      <pubDate>Wed, 16 Apr 2025 07:51:31 +0000</pubDate>
      <link>https://dev.to/sanskar_singh_3e842eec7e6/log-insign-up-4o35</link>
      <guid>https://dev.to/sanskar_singh_3e842eec7e6/log-insign-up-4o35</guid>
      <description>&lt;p&gt;//DatabaseHelper.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.yourapp;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.*;

public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "UserDB.db";
    public static final String TABLE_NAME = "users";
    public static final String COL_1 = "ID";
    public static final String COL_2 = "USERNAME";
    public static final String COL_3 = "PASSWORD";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, USERNAME TEXT, PASSWORD TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public boolean insertUser(String username, String password) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(COL_2, username);
        contentValues.put(COL_3, password);
        long result = db.insert(TABLE_NAME, null, contentValues);
        return result != -1;
    }

    public boolean checkUser(String username, String password) {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE USERNAME=? AND PASSWORD=?", new String[]{username, password});
        return cursor.getCount() &amp;gt; 0;
    }

    public boolean userExists(String username) {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE USERNAME=?", new String[]{username});
        return cursor.getCount() &amp;gt; 0;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//LoginActivity.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.yourapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

    EditText username, password;
    Button loginBtn, signupRedirectBtn;
    DatabaseHelper db;

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

        username = findViewById(R.id.etUsername);
        password = findViewById(R.id.etPassword);
        loginBtn = findViewById(R.id.btnLogin);
        signupRedirectBtn = findViewById(R.id.btnSignupRedirect);

        db = new DatabaseHelper(this);

        loginBtn.setOnClickListener(v -&amp;gt; {
            String user = username.getText().toString();
            String pass = password.getText().toString();

            if (db.checkUser(user, pass)) {
                Toast.makeText(LoginActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                finish();
            } else {
                Toast.makeText(LoginActivity.this, "Invalid credentials", Toast.LENGTH_SHORT).show();
            }
        });

        signupRedirectBtn.setOnClickListener(v -&amp;gt; startActivity(new Intent(LoginActivity.this, SignupActivity.class)));
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//SignupActivity&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.yourapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class SignupActivity extends AppCompatActivity {

    EditText username, password, confirmPassword;
    Button signupBtn;
    DatabaseHelper db;

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

        username = findViewById(R.id.etUsernameSignup);
        password = findViewById(R.id.etPasswordSignup);
        confirmPassword = findViewById(R.id.etConfirmPassword);
        signupBtn = findViewById(R.id.btnSignup);

        db = new DatabaseHelper(this);

        signupBtn.setOnClickListener(v -&amp;gt; {
            String user = username.getText().toString();
            String pass = password.getText().toString();
            String cpass = confirmPassword.getText().toString();

            if (user.equals("") || pass.equals("") || cpass.equals("")) {
                Toast.makeText(SignupActivity.this, "All fields are required", Toast.LENGTH_SHORT).show();
            } else if (!pass.equals(cpass)) {
                Toast.makeText(SignupActivity.this, "Passwords do not match", Toast.LENGTH_SHORT).show();
            } else if (db.userExists(user)) {
                Toast.makeText(SignupActivity.this, "User already exists", Toast.LENGTH_SHORT).show();
            } else {
                if (db.insertUser(user, pass)) {
                    Toast.makeText(SignupActivity.this, "Signup Successful", Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(SignupActivity.this, LoginActivity.class));
                    finish();
                } else {
                    Toast.makeText(SignupActivity.this, "Signup Failed", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//activity_login.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;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="24dp"
    android:gravity="center"&amp;gt;

    &amp;lt;EditText
        android:id="@+id/etUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username" /&amp;gt;

    &amp;lt;EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:inputType="textPassword" /&amp;gt;

    &amp;lt;Button
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login" /&amp;gt;

    &amp;lt;Button
        android:id="@+id/btnSignupRedirect"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="No account? Sign up" /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//activity_signup.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;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="24dp"
    android:gravity="center"&amp;gt;

    &amp;lt;EditText
        android:id="@+id/etUsernameSignup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username" /&amp;gt;

    &amp;lt;EditText
        android:id="@+id/etPasswordSignup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:inputType="textPassword" /&amp;gt;

    &amp;lt;EditText
        android:id="@+id/etConfirmPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:inputType="textPassword" /&amp;gt;

    &amp;lt;Button
        android:id="@+id/btnSignup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Sign Up" /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Steps to Integrate Login/Signup&lt;/p&gt;

&lt;p&gt;🔹 1. Add Activities to AndroidManifest.xml&lt;br&gt;
Open AndroidManifest.xml and add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;application ... &amp;gt;

    &amp;lt;activity android:name=".MainActivity" /&amp;gt;
    &amp;lt;activity android:name=".SignupActivity" /&amp;gt;
    &amp;lt;activity android:name=".LoginActivity"&amp;gt;
        &amp;lt;intent-filter&amp;gt;
            &amp;lt;action android:name="android.intent.action.MAIN" /&amp;gt;
            &amp;lt;category android:name="android.intent.category.LAUNCHER" /&amp;gt;
        &amp;lt;/intent-filter&amp;gt;
    &amp;lt;/activity&amp;gt;

&amp;lt;/application&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes LoginActivity the first screen when the app launches.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Connect to Your Main App Screen
Let’s say your main screen is MainActivity.java, already existing. In LoginActivity.java, modify this part:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (db.checkUser(user, pass)) {
    Toast.makeText(LoginActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(LoginActivity.this, MainActivity.class);
    intent.putExtra("username", user); // optional
    startActivity(intent);
    finish(); // prevent back navigation to login
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Access the Logged-in User in MainActivity (Optional)
In MainActivity.java, you can get the logged-in username:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String username = getIntent().getStringExtra("username");
TextView welcome = findViewById(R.id.tvWelcome);
welcome.setText("Welcome, " + username + "!");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;(Optional) Add a Logout Button in MainActivity
To go back to login screen:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Button logoutBtn = findViewById(R.id.btnLogout);
logoutBtn.setOnClickListener(v -&amp;gt; {
    Intent intent = new Intent(MainActivity.this, LoginActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // clear back stack
    startActivity(intent);
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add the DatabaseHelper.java to Your java Folder&lt;br&gt;
Just right-click your java package, choose New &amp;gt; Java Class, name it DatabaseHelper, and paste the provided code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add XML Layouts&lt;br&gt;
Copy:&lt;br&gt;
activity_login.xml → res/layout/activity_login.xml&lt;br&gt;
activity_signup.xml → res/layout/activity_signup.xml&lt;br&gt;
Use the layout editor or just paste the XML directly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>loginhelp</category>
      <category>signuphelp</category>
    </item>
    <item>
      <title>Movie Review</title>
      <dc:creator>Sanskar Singh</dc:creator>
      <pubDate>Wed, 16 Apr 2025 03:38:08 +0000</pubDate>
      <link>https://dev.to/sanskar_singh_3e842eec7e6/movie-review-bef</link>
      <guid>https://dev.to/sanskar_singh_3e842eec7e6/movie-review-bef</guid>
      <description>&lt;p&gt;//main_activity.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.moviereview;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText movieNameEditText, movieYearEditText, movieReviewEditText;
    private RatingBar movieRatingBar;
    private Button saveReviewButton, viewReviewsButton;
    private TextView detailsHeaderTextView, movieDetailsTextView;
    private ScrollView movieDetailsScrollView;
    private LinearLayout addReviewLayout;

    private SQLiteDatabase database;

    private static final String DATABASE_NAME = "MovieReviews";
    private static final String TABLE_REVIEWS = "reviews";
    private static final String COLUMN_NAME = "name";
    private static final String COLUMN_YEAR = "year";
    private static final String COLUMN_RATING = "rating";
    private static final String COLUMN_REVIEW = "review";

    private boolean isInViewMode = false;

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

        movieNameEditText = findViewById(R.id.movieNameEditText);
        movieYearEditText = findViewById(R.id.movieYearEditText);
        movieReviewEditText = findViewById(R.id.movieReviewEditText);
        movieRatingBar = findViewById(R.id.movieRatingBar);
        saveReviewButton = findViewById(R.id.saveReviewButton);
        viewReviewsButton = findViewById(R.id.viewReviewsButton);
        detailsHeaderTextView = findViewById(R.id.detailsHeaderTextView);
        movieDetailsTextView = findViewById(R.id.movieDetailsTextView);
        movieDetailsScrollView = findViewById(R.id.movieDetailsScrollView);
        addReviewLayout = findViewById(R.id.addReviewLayout);

        database = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);

        database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_REVIEWS + " (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                COLUMN_NAME + " TEXT UNIQUE, " +
                COLUMN_YEAR + " INTEGER, " +
                COLUMN_RATING + " REAL, " +
                COLUMN_REVIEW + " TEXT)");

        saveReviewButton.setOnClickListener(v -&amp;gt; saveMovieReview());
        viewReviewsButton.setOnClickListener(v -&amp;gt; toggleViewMode());
    }

    private void saveMovieReview() {
        String name = movieNameEditText.getText().toString().trim();
        String yearStr = movieYearEditText.getText().toString().trim();
        String review = movieReviewEditText.getText().toString().trim();
        float rating = movieRatingBar.getRating();

        if (name.isEmpty() || yearStr.isEmpty()) {
            Toast.makeText(this, "Please enter movie name and year", Toast.LENGTH_SHORT).show();
            return;
        }

        try {
            int year = Integer.parseInt(yearStr);

            ContentValues values = new ContentValues();
            values.put(COLUMN_NAME, name);
            values.put(COLUMN_YEAR, year);
            values.put(COLUMN_RATING, rating);
            values.put(COLUMN_REVIEW, review);

            long id = database.insertWithOnConflict(TABLE_REVIEWS, null, values, SQLiteDatabase.CONFLICT_REPLACE);

            if (id == -1) {
                Toast.makeText(this, "Error saving review", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "Review saved", Toast.LENGTH_SHORT).show();
            }

            movieNameEditText.setText("");
            movieYearEditText.setText("");
            movieReviewEditText.setText("");
            movieRatingBar.setRating(0);

        } catch (NumberFormatException e) {
            Toast.makeText(this, "Invalid year", Toast.LENGTH_SHORT).show();
        }
    }

    private void toggleViewMode() {
        isInViewMode = !isInViewMode;

        if (isInViewMode) {
            addReviewLayout.setVisibility(View.GONE);
            detailsHeaderTextView.setVisibility(View.VISIBLE);
            movieDetailsScrollView.setVisibility(View.VISIBLE);
            viewReviewsButton.setText("Add Review");
            displayAllReviews();
        } else {
            addReviewLayout.setVisibility(View.VISIBLE);
            detailsHeaderTextView.setVisibility(View.GONE);
            movieDetailsScrollView.setVisibility(View.GONE);
            viewReviewsButton.setText("View Reviews");
        }
    }

    private void displayAllReviews() {
        Cursor cursor = database.rawQuery("SELECT * FROM " + TABLE_REVIEWS + " ORDER BY " + COLUMN_NAME, null);
        StringBuilder builder = new StringBuilder();

        if (cursor.moveToFirst()) {
            do {
                String name = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME));
                int year = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_YEAR));
                float rating = cursor.getFloat(cursor.getColumnIndexOrThrow(COLUMN_RATING));
                String review = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_REVIEW));

                builder.append("🎬 ").append(name).append(" (").append(year).append(")\n");
                builder.append("⭐ Rating: ").append(rating).append("/5\n");
                builder.append("📝 Review: ").append(review).append("\n\n");
            } while (cursor.moveToNext());
        } else {
            builder.append("No reviews found.");
        }

        cursor.close();
        movieDetailsTextView.setText(builder.toString());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        database.close();
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//mainactivity.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity"&amp;gt;

    &amp;lt;!-- App Title --&amp;gt;
    &amp;lt;TextView
        android:id="@+id/appTitleTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Movie Review"
        android:textSize="24sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginBottom="16dp" /&amp;gt;

    &amp;lt;!-- Add Review Section --&amp;gt;
    &amp;lt;LinearLayout
        android:id="@+id/addReviewLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@id/appTitleTextView"&amp;gt;

        &amp;lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Movie Name:"
            android:textStyle="bold" /&amp;gt;

        &amp;lt;EditText
            android:id="@+id/movieNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter movie name"
            android:minHeight="48dp"
            android:inputType="text"
            android:layout_marginBottom="8dp" /&amp;gt;

        &amp;lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Year:"
            android:textStyle="bold" /&amp;gt;

        &amp;lt;EditText
            android:id="@+id/movieYearEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter release year"
            android:minHeight="48dp"
            android:inputType="number"
            android:maxLength="4"
            android:layout_marginBottom="8dp" /&amp;gt;

        &amp;lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rating:"
            android:textStyle="bold" /&amp;gt;

        &amp;lt;RatingBar
            android:id="@+id/movieRatingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="0.5"
            android:layout_marginBottom="8dp"
            android:contentDescription="Rate movie from 1 to 5 stars" /&amp;gt;

        &amp;lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Review:"
            android:textStyle="bold" /&amp;gt;

        &amp;lt;EditText
            android:id="@+id/movieReviewEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Write your review"
            android:minHeight="96dp"
            android:inputType="textMultiLine"
            android:gravity="top|start"
            android:padding="8dp"
            android:layout_marginBottom="16dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/saveReviewButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Save Review"
            android:minHeight="48dp" /&amp;gt;
    &amp;lt;/LinearLayout&amp;gt;

    &amp;lt;!-- View Reviews Header --&amp;gt;
    &amp;lt;TextView
        android:id="@+id/detailsHeaderTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="All Reviews"
        android:textSize="18sp"
        android:textStyle="bold"
        android:layout_below="@id/addReviewLayout"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="8dp"
        android:visibility="gone" /&amp;gt;

    &amp;lt;!-- Scrollable Review Display --&amp;gt;
    &amp;lt;ScrollView
        android:id="@+id/movieDetailsScrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/detailsHeaderTextView"
        android:layout_above="@id/viewReviewsButton"
        android:layout_marginBottom="8dp"
        android:visibility="gone"&amp;gt;

        &amp;lt;TextView
            android:id="@+id/movieDetailsTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:background="#F0F0F0"
            android:textSize="16sp" /&amp;gt;
    &amp;lt;/ScrollView&amp;gt;

    &amp;lt;!-- Toggle Button --&amp;gt;
    &amp;lt;Button
        android:id="@+id/viewReviewsButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="View Reviews"
        android:minHeight="48dp"
        android:layout_alignParentBottom="true" /&amp;gt;
&amp;lt;/RelativeLayout&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mrhelp</category>
    </item>
    <item>
      <title>Grocery List</title>
      <dc:creator>Sanskar Singh</dc:creator>
      <pubDate>Wed, 16 Apr 2025 03:36:33 +0000</pubDate>
      <link>https://dev.to/sanskar_singh_3e842eec7e6/grocery-list-3a55</link>
      <guid>https://dev.to/sanskar_singh_3e842eec7e6/grocery-list-3a55</guid>
      <description>&lt;p&gt;// MainActivity.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.grocerylist;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private EditText itemNameEditText;
    private EditText itemCostEditText;
    private Button addItemButton;
    private Spinner itemsSpinner;
    private LinearLayout selectedItemsLayout;
    private TextView totalCostTextView;
    private Button calculateTotalButton;

    private SQLiteDatabase database;
    private static final String DATABASE_NAME = "GroceryList";
    private static final String TABLE_GROCERY = "grocery_items";
    private static final String COLUMN_ID = "id";
    private static final String COLUMN_NAME = "name";
    private static final String COLUMN_COST = "cost";

    private List&amp;lt;String&amp;gt; itemNames = new ArrayList&amp;lt;&amp;gt;();
    private Map&amp;lt;String, Double&amp;gt; itemCosts = new HashMap&amp;lt;&amp;gt;();
    private Map&amp;lt;String, Boolean&amp;gt; selectedItems = new HashMap&amp;lt;&amp;gt;();

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

        // Initialize UI elements
        itemNameEditText = findViewById(R.id.itemNameEditText);
        itemCostEditText = findViewById(R.id.itemCostEditText);
        addItemButton = findViewById(R.id.addItemButton);
        itemsSpinner = findViewById(R.id.itemsSpinner);
        selectedItemsLayout = findViewById(R.id.selectedItemsLayout);
        totalCostTextView = findViewById(R.id.totalCostTextView);
        calculateTotalButton = findViewById(R.id.calculateTotalButton);

        // Create or open the database
        database = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);

        // Create the grocery table if it doesn't exist
        database.execSQL(
                "CREATE TABLE IF NOT EXISTS " + TABLE_GROCERY + " (" +
                        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        COLUMN_NAME + " TEXT UNIQUE, " +
                        COLUMN_COST + " REAL)");

        // Load grocery items from database
        loadGroceryItems();

        // Set up spinner
        setupSpinner();

        // Add item button click listener
        addItemButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addGroceryItem();
            }
        });

        // Calculate total button click listener
        calculateTotalButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                calculateTotal();
            }
        });
    }

    private void setupSpinner() {
        ArrayAdapter&amp;lt;String&amp;gt; adapter = new ArrayAdapter&amp;lt;&amp;gt;(
                this, android.R.layout.simple_spinner_item, itemNames);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        itemsSpinner.setAdapter(adapter);

        itemsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView&amp;lt;?&amp;gt; parent, View view, int position, long id) {
                String selectedItem = itemNames.get(position);
                addItemToSelection(selectedItem);
            }

            @Override
            public void onNothingSelected(AdapterView&amp;lt;?&amp;gt; parent) {
                // Do nothing
            }
        });
    }

    private void loadGroceryItems() {
        // Clear existing data
        itemNames.clear();
        itemCosts.clear();

        // Query all items from the database
        Cursor cursor = database.rawQuery("SELECT * FROM " + TABLE_GROCERY, null);

        if (cursor.moveToFirst()) {
            int nameIndex = cursor.getColumnIndex(COLUMN_NAME);
            int costIndex = cursor.getColumnIndex(COLUMN_COST);

            if (nameIndex &amp;gt;= 0 &amp;amp;&amp;amp; costIndex &amp;gt;= 0) {
                do {
                    String name = cursor.getString(nameIndex);
                    double cost = cursor.getDouble(costIndex);

                    itemNames.add(name);
                    itemCosts.put(name, cost);
                } while (cursor.moveToNext());
            }
        }

        cursor.close();
    }

    private void addGroceryItem() {
        String itemName = itemNameEditText.getText().toString().trim();
        String costString = itemCostEditText.getText().toString().trim();

        if (itemName.isEmpty() || costString.isEmpty()) {
            Toast.makeText(this, "Please enter both item name and cost", Toast.LENGTH_SHORT).show();
            return;
        }

        try {
            double cost = Double.parseDouble(costString);

            ContentValues values = new ContentValues();
            values.put(COLUMN_NAME, itemName);
            values.put(COLUMN_COST, cost);

            // Try to insert the item
            long result = database.insert(TABLE_GROCERY, null, values);

            if (result == -1) {
                // If insert failed, try to update instead (item might already exist)
                int updateResult = database.update(TABLE_GROCERY, values, COLUMN_NAME + " = ?",
                        new String[]{itemName});

                if (updateResult &amp;gt; 0) {
                    Toast.makeText(this, "Item updated successfully", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this, "Failed to add item", Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Toast.makeText(this, "Item added successfully", Toast.LENGTH_SHORT).show();
            }

            // Clear input fields
            itemNameEditText.setText("");
            itemCostEditText.setText("");

            // Reload grocery items
            loadGroceryItems();

            // Update spinner
            ((ArrayAdapter) itemsSpinner.getAdapter()).notifyDataSetChanged();

        } catch (NumberFormatException e) {
            Toast.makeText(this, "Please enter a valid cost", Toast.LENGTH_SHORT).show();
        }
    }

    private void addItemToSelection(final String itemName) {
        // Check if the item is already in the selection layout
        for (int i = 0; i &amp;lt; selectedItemsLayout.getChildCount(); i++) {
            View view = selectedItemsLayout.getChildAt(i);
            if (view instanceof CheckBox) {
                CheckBox checkBox = (CheckBox) view;
                if (checkBox.getText().toString().equals(itemName)) {
                    // Item already exists in selection, just return
                    return;
                }
            }
        }

        // Create a new checkbox for the selected item
        final CheckBox itemCheckBox = new CheckBox(this);
        itemCheckBox.setText(itemName);
        itemCheckBox.setChecked(true);

        // Add the item to the selected items map
        selectedItems.put(itemName, true);

        // Set checkbox change listener
        itemCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -&amp;gt; {
            selectedItems.put(itemName, isChecked);
        });

        // Add checkbox to layout
        selectedItemsLayout.addView(itemCheckBox);
    }

    private void calculateTotal() {
        double total = 0.0;

        // Iterate through selected items
        for (Map.Entry&amp;lt;String, Boolean&amp;gt; entry : selectedItems.entrySet()) {
            if (entry.getValue()) {
                String itemName = entry.getKey();
                Double cost = itemCosts.get(itemName);
                if (cost != null) {
                    total += cost;
                }
            }
        }

        // Display the total cost
        totalCostTextView.setText(String.format("Total Cost: $%.2f", total));
    }

    @Override
    protected void onDestroy() {
        database.close();
        super.onDestroy();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//main_activity.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    tools:context=".MainActivity"&amp;gt;

    &amp;lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Grocery List"
        android:textSize="24sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginBottom="16dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add Grocery Item"
        android:textSize="18sp"
        android:textStyle="bold"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginBottom="8dp"&amp;gt;

        &amp;lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Item Name:"
            android:layout_gravity="center_vertical" /&amp;gt;

        &amp;lt;EditText
            android:id="@+id/itemNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter item name"
            android:minHeight="48dp"
            android:inputType="text"
            android:layout_marginStart="8dp" /&amp;gt;
    &amp;lt;/LinearLayout&amp;gt;

    &amp;lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginBottom="16dp"&amp;gt;

        &amp;lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Item Cost: $"
            android:layout_gravity="center_vertical" /&amp;gt;

        &amp;lt;EditText
            android:id="@+id/itemCostEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter cost"
            android:minHeight="48dp"
            android:inputType="numberDecimal"
            android:layout_marginStart="8dp" /&amp;gt;
    &amp;lt;/LinearLayout&amp;gt;

    &amp;lt;Button
        android:id="@+id/addItemButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add Item"
        android:minHeight="48dp"
        android:layout_marginBottom="24dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Select Items"
        android:textSize="18sp"
        android:textStyle="bold"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;Spinner
        android:id="@+id/itemsSpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="48dp"
        android:layout_marginBottom="16dp" /&amp;gt;

    &amp;lt;TextView
        android:id="@+id/selectedItemsLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Selected Items"
        android:textSize="18sp"
        android:textStyle="bold"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:contentDescription="List of selected grocery items"
        android:importantForAccessibility="yes"
        android:labelFor="@id/selectedItemsLayout"&amp;gt;

        &amp;lt;LinearLayout
            android:id="@+id/selectedItemsLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" /&amp;gt;
    &amp;lt;/ScrollView&amp;gt;

    &amp;lt;Button
        android:id="@+id/calculateTotalButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Calculate Total"
        android:minHeight="48dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;TextView
        android:id="@+id/totalCostTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Total Cost: $0.00"
        android:textSize="20sp"
        android:textStyle="bold"
        android:gravity="center" /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>glhelp</category>
    </item>
    <item>
      <title>Task Manager</title>
      <dc:creator>Sanskar Singh</dc:creator>
      <pubDate>Wed, 16 Apr 2025 03:32:29 +0000</pubDate>
      <link>https://dev.to/sanskar_singh_3e842eec7e6/task-manager-487d</link>
      <guid>https://dev.to/sanskar_singh_3e842eec7e6/task-manager-487d</guid>
      <description>&lt;p&gt;// MainActivity.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.taskmanager;

import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private EditText taskNameEditText;
    private DatePicker dueDatePicker;
    private Spinner prioritySpinner;
    private Button saveTaskButton;
    private ListView tasksListView;

    private SQLiteDatabase database;
    private ArrayList&amp;lt;Map&amp;lt;String, String&amp;gt;&amp;gt; tasksList;
    private SimpleAdapter adapter;

    private static final String DATABASE_NAME = "TaskManager";
    private static final String TABLE_TASKS = "tasks";
    private static final String COLUMN_ID = "id";
    private static final String COLUMN_NAME = "name";
    private static final String COLUMN_DATE = "date";
    private static final String COLUMN_PRIORITY = "priority";

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

        // Initialize UI elements
        taskNameEditText = findViewById(R.id.taskNameEditText);
        dueDatePicker = findViewById(R.id.dueDatePicker);
        prioritySpinner = findViewById(R.id.prioritySpinner);
        saveTaskButton = findViewById(R.id.saveTaskButton);
        tasksListView = findViewById(R.id.tasksListView);

        // Set up priority spinner
        ArrayAdapter&amp;lt;CharSequence&amp;gt; priorityAdapter = ArrayAdapter.createFromResource(
                this, R.array.priority_levels, android.R.layout.simple_spinner_item);
        priorityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        prioritySpinner.setAdapter(priorityAdapter);

        // Create or open the database
        database = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);

        // Create the tasks table if it doesn't exist
        database.execSQL(
                "CREATE TABLE IF NOT EXISTS " + TABLE_TASKS + " (" +
                        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        COLUMN_NAME + " TEXT, " +
                        COLUMN_DATE + " TEXT, " +
                        COLUMN_PRIORITY + " TEXT)");

        // Initialize tasks list and adapter
        tasksList = new ArrayList&amp;lt;&amp;gt;();
        adapter = new SimpleAdapter(
                this,
                tasksList,
                R.layout.task_item,
                new String[]{"name", "date", "priority", "id"},
                new int[]{R.id.taskNameTextView, R.id.taskDateTextView, R.id.taskPriorityTextView, R.id.taskIdTextView}
        );
        tasksListView.setAdapter(adapter);

        loadTasks(); // Load existing tasks

        // Save task button click listener
        saveTaskButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveTask();
            }
        });

        // Set item click listener for editing or deleting tasks
        tasksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView&amp;lt;?&amp;gt; parent, View view, int position, long id) {
                showTaskOptionsDialog(position);
            }
        });
    }

    private String getFormattedDate() {
        int day = dueDatePicker.getDayOfMonth();
        int month = dueDatePicker.getMonth();
        int year = dueDatePicker.getYear();

        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return dateFormat.format(calendar.getTime());
    }

    private void saveTask() {
        String taskName = taskNameEditText.getText().toString().trim();
        String dueDate = getFormattedDate();
        String priority = prioritySpinner.getSelectedItem().toString();

        if (taskName.isEmpty()) {
            Toast.makeText(this, "Please enter a task name", Toast.LENGTH_SHORT).show();
            return;
        }

        ContentValues values = new ContentValues();
        values.put(COLUMN_NAME, taskName);
        values.put(COLUMN_DATE, dueDate);
        values.put(COLUMN_PRIORITY, priority);

        long result = database.insert(TABLE_TASKS, null, values);

        if (result != -1) {
            Toast.makeText(this, "Task saved successfully", Toast.LENGTH_SHORT).show();
            taskNameEditText.setText("");
            loadTasks();
        } else {
            Toast.makeText(this, "Failed to save task", Toast.LENGTH_SHORT).show();
        }
    }

    private void loadTasks() {
        tasksList.clear();

        Cursor cursor = database.rawQuery("SELECT * FROM " + TABLE_TASKS, null);

        if (cursor.moveToFirst()) {
            int idIndex = cursor.getColumnIndex(COLUMN_ID);
            int nameIndex = cursor.getColumnIndex(COLUMN_NAME);
            int dateIndex = cursor.getColumnIndex(COLUMN_DATE);
            int priorityIndex = cursor.getColumnIndex(COLUMN_PRIORITY);

            // Only proceed if all column indices are valid
            if (idIndex &amp;gt;= 0 &amp;amp;&amp;amp; nameIndex &amp;gt;= 0 &amp;amp;&amp;amp; dateIndex &amp;gt;= 0 &amp;amp;&amp;amp; priorityIndex &amp;gt;= 0) {
                do {
                    int id = cursor.getInt(idIndex);
                    String name = cursor.getString(nameIndex);
                    String date = cursor.getString(dateIndex);
                    String priority = cursor.getString(priorityIndex);

                    Map&amp;lt;String, String&amp;gt; task = new HashMap&amp;lt;&amp;gt;();
                    task.put("id", String.valueOf(id));
                    task.put("name", name);
                    task.put("date", "Due: " + date);
                    task.put("priority", "Priority: " + priority);

                    tasksList.add(task);
                } while (cursor.moveToNext());
            } else {
                Toast.makeText(this, "Database schema error", Toast.LENGTH_SHORT).show();
            }
        }

        cursor.close();
        adapter.notifyDataSetChanged();
    }

    private void showTaskOptionsDialog(final int position) {
        final String taskId = tasksList.get(position).get("id");

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Task Options")
                .setItems(new CharSequence[]{"Edit", "Delete"}, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            // Edit option selected
                            showEditTaskDialog(Integer.parseInt(taskId));
                        } else {
                            // Delete option selected
                            deleteTask(Integer.parseInt(taskId));
                        }
                    }
                })
                .setNegativeButton("Cancel", null)
                .show();
    }

    private void showEditTaskDialog(final int taskId) {
        // Get the task details from database
        Cursor cursor = database.rawQuery("SELECT * FROM " + TABLE_TASKS + " WHERE " + COLUMN_ID + " = ?",
                new String[]{String.valueOf(taskId)});

        if (cursor.moveToFirst()) {
            int nameIndex = cursor.getColumnIndex(COLUMN_NAME);
            int dateIndex = cursor.getColumnIndex(COLUMN_DATE);
            int priorityIndex = cursor.getColumnIndex(COLUMN_PRIORITY);

            // Check if all column indices are valid
            if (nameIndex &amp;gt;= 0 &amp;amp;&amp;amp; dateIndex &amp;gt;= 0 &amp;amp;&amp;amp; priorityIndex &amp;gt;= 0) {
                String name = cursor.getString(nameIndex);
                String date = cursor.getString(dateIndex);
                String priority = cursor.getString(priorityIndex);

                // Inflate the edit task dialog layout
                View dialogView = LayoutInflater.from(this).inflate(R.layout.edit_task_dialog, null);
                final EditText editTaskName = dialogView.findViewById(R.id.editTaskNameEditText);
                final DatePicker editDueDate = dialogView.findViewById(R.id.editDueDatePicker);
                final Spinner editPrioritySpinner = dialogView.findViewById(R.id.editPrioritySpinner);

                // Set current values
                editTaskName.setText(name);

                // Parse the date and set date picker
                try {
                    String[] dateParts = date.split("-");
                    int year = Integer.parseInt(dateParts[0]);
                    int month = Integer.parseInt(dateParts[1]) - 1; // DatePicker months are 0-based
                    int day = Integer.parseInt(dateParts[2]);
                    editDueDate.updateDate(year, month, day);
                } catch (Exception e) {
                    // Use current date if parsing fails
                }

                // Set up priority spinner
                ArrayAdapter&amp;lt;CharSequence&amp;gt; priorityAdapter = ArrayAdapter.createFromResource(
                        this, R.array.priority_levels, android.R.layout.simple_spinner_item);
                priorityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                editPrioritySpinner.setAdapter(priorityAdapter);

                // Set selected priority
                for (int i = 0; i &amp;lt; editPrioritySpinner.getCount(); i++) {
                    if (editPrioritySpinner.getItemAtPosition(i).toString().equals(priority)) {
                        editPrioritySpinner.setSelection(i);
                        break;
                    }
                }

                // Show dialog
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Edit Task")
                        .setView(dialogView)
                        .setPositiveButton("Save", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // Get edited values
                                String updatedName = editTaskName.getText().toString().trim();

                                // Get formatted date
                                int day = editDueDate.getDayOfMonth();
                                int month = editDueDate.getMonth();
                                int year = editDueDate.getYear();

                                Calendar calendar = Calendar.getInstance();
                                calendar.set(year, month, day);

                                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
                                String updatedDate = dateFormat.format(calendar.getTime());

                                String updatedPriority = editPrioritySpinner.getSelectedItem().toString();

                                // Update the task in database
                                updateTask(taskId, updatedName, updatedDate, updatedPriority);
                            }
                        })
                        .setNegativeButton("Cancel", null)
                        .show();
            } else {
                Toast.makeText(this, "Could not load task details", Toast.LENGTH_SHORT).show();
            }
        }

        cursor.close();
    }

    private void updateTask(int taskId, String name, String date, String priority) {
        ContentValues values = new ContentValues();
        values.put(COLUMN_NAME, name);
        values.put(COLUMN_DATE, date);
        values.put(COLUMN_PRIORITY, priority);

        int result = database.update(TABLE_TASKS, values, COLUMN_ID + " = ?",
                new String[]{String.valueOf(taskId)});

        if (result &amp;gt; 0) {
            Toast.makeText(this, "Task updated successfully", Toast.LENGTH_SHORT).show();
            loadTasks();
        } else {
            Toast.makeText(this, "Failed to update task", Toast.LENGTH_SHORT).show();
        }
    }

    private void deleteTask(int taskId) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Confirm Delete")
                .setMessage("Are you sure you want to delete this task?")
                .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        int result = database.delete(TABLE_TASKS, COLUMN_ID + " = ?",
                                new String[]{String.valueOf(taskId)});

                        if (result &amp;gt; 0) {
                            Toast.makeText(MainActivity.this, "Task deleted successfully", Toast.LENGTH_SHORT).show();
                            loadTasks();
                        } else {
                            Toast.makeText(MainActivity.this, "Failed to delete task", Toast.LENGTH_SHORT).show();
                        }
                    }
                })
                .setNegativeButton("Cancel", null)
                .show();
    }

    @Override
    protected void onDestroy() {
        database.close();
        super.onDestroy();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;// activity_main.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    tools:context=".MainActivity"&amp;gt;

    &amp;lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Task Manager"
        android:textSize="24sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginBottom="16dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Task Name:"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;EditText
        android:id="@+id/taskNameEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter task name"
        android:minHeight="48dp"
        android:padding="8dp"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Due Date:"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;DatePicker
        android:id="@+id/dueDatePicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:datePickerMode="spinner"
        android:calendarViewShown="false"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Priority:"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;Spinner
        android:id="@+id/prioritySpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="48dp"
        android:padding="8dp"
        android:layout_marginBottom="16dp" /&amp;gt;

    &amp;lt;Button
        android:id="@+id/saveTaskButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save Task"
        android:layout_marginBottom="16dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Tasks:"
        android:textStyle="bold"
        android:textSize="18sp" /&amp;gt;

    &amp;lt;ListView
        android:id="@+id/tasksListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//edit_task_dialog.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="16dp"&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Task Name:"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;EditText
        android:id="@+id/editTaskNameEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter task name"
        android:minHeight="48dp"
        android:padding="8dp"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Due Date:"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;DatePicker
        android:id="@+id/editDueDatePicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:datePickerMode="spinner"
        android:calendarViewShown="false"
        android:layout_marginBottom="8dp" /&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Priority:"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;Spinner
        android:id="@+id/editPrioritySpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="48dp"
        android:layout_marginBottom="8dp" /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//task_item.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp"&amp;gt;

    &amp;lt;TextView
        android:id="@+id/taskNameTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:textStyle="bold" /&amp;gt;

    &amp;lt;TextView
        android:id="@+id/taskDateTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp" /&amp;gt;

    &amp;lt;TextView
        android:id="@+id/taskPriorityTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp" /&amp;gt;

    &amp;lt;TextView
        android:id="@+id/taskIdTextView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:visibility="gone" /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//strings.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;resources&amp;gt;
    &amp;lt;string name="app_name"&amp;gt;Task Manager&amp;lt;/string&amp;gt;
    &amp;lt;string-array name="priority_levels"&amp;gt;
        &amp;lt;item&amp;gt;High&amp;lt;/item&amp;gt;
        &amp;lt;item&amp;gt;Medium&amp;lt;/item&amp;gt;
       &amp;lt;item&amp;gt;Low&amp;lt;/item&amp;gt;
    &amp;lt;/string-array&amp;gt;
&amp;lt;/resources&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tmhelp</category>
    </item>
  </channel>
</rss>
