Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:01:10+00:00 2026-06-13T13:01:10+00:00

I have a question. I have a sqlite database in my project. I am

  • 0

I have a question. I have a sqlite database in my project. I am select data in database and transfer the custom listview. My Custom ListView has got a delete button. When I press the button, my CostumListView class is delete this row. But Listview is the same. I want to make refresh listview after delete process.

This is my LAUNCHER Class (TaskList.java):

package com.nano.tasklist;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class TaskList extends Activity {

ArrayList<CategoryInfo> CategoryList;

TaskListDatabase DatabaseActivity;

private CategoryAdapter CategoryAdapter = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_list);

    DatabaseActivity = new TaskListDatabase(this);

    CategoryInsert("School","21.02.2012","YES");
    CategoryInsert("House","21.02.2012","NO");
    CategoryInsert("Park","21.02.2012","YES");

    ListView lvCategories = (ListView) findViewById(R.id.lvCategories);

    CategoryList = new ArrayList<CategoryInfo>();

    CategoryAdapter = new CategoryAdapter(this, R.layout.category_row, CategoryList);
    lvCategories.setAdapter(this.CategoryAdapter);

    CategorySelect();
}

public void CategorySelect(){
    String[] Column = {"ID","Category","AddDate","Completed"};

    Cursor Result = null;

    try{
        SQLiteDatabase Database = DatabaseActivity.getReadableDatabase();

        Result = Database.query("Category", Column, null, null, null, null, null);

        startManagingCursor(Result);

        while(Result.moveToNext()){
            CategoryInfo Info = new CategoryInfo();

            CategoryList = new ArrayList<CategoryInfo>();

            Info.setID(Result.getString(Result.getColumnIndex("ID")));
            Info.setCategory(Result.getString(Result.getColumnIndex("Category")));
            Info.setAddDate(Result.getString(Result.getColumnIndex("AddDate")));
            Info.setCompleted(Result.getString(Result.getColumnIndex("Completed")));

            CategoryList.add(Info);

            if(CategoryList != null && CategoryList.size() > 0){
                CategoryAdapter.add(CategoryList.get(0));
                CategoryAdapter.notifyDataSetChanged();
            }
        }
    } catch (SQLiteException Error) {
        Toast.makeText(getApplicationContext(), "Error (CategorySelect) : " + Error.toString(), Toast.LENGTH_LONG).show();

        Result = null;
    }
}

public boolean CategoryInsert(String Category, String AddDate, String Completed){
    boolean Result;

    try{
        SQLiteDatabase Database = DatabaseActivity.getWritableDatabase();

        ContentValues Values = new ContentValues();

        Values.put("Category", Category);
        Values.put("AddDate", AddDate);
        Values.put("Completed", Completed);

        Database.insert("Category", null, Values);

        Result = true;
    } catch (SQLiteException Error) {
        Toast.makeText(getApplicationContext(), "Error (CategoryInsert) : " + Error.toString(), Toast.LENGTH_LONG).show();

        Result = false;
    }

    return Result;
}

This is my CustomListAdapter class (CategoryAdapter.java)

package com.nano.tasklist;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

public class CategoryAdapter extends ArrayAdapter<CategoryInfo>{

private Context ActivityContext = null;
private ArrayList<CategoryInfo> Items = null;

TaskListDatabase DatabaseActivity;

public CategoryAdapter(Context Context, int textViewResourceId, ArrayList<CategoryInfo> Items){
    super(Context,textViewResourceId,Items);

    this.ActivityContext = Context;
    this.Items=Items;

    DatabaseActivity = new TaskListDatabase(Context);
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View MainView = convertView;

    if (MainView == null) {
        LayoutInflater Layout = (LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        MainView = Layout.inflate(R.layout.category_row, null);
    }

    final CategoryInfo Item = Items.get(position);

    if (Item != null) {

        final CheckBox cbCompleted = (CheckBox) MainView.findViewById(R.id.cbCategoryCompleted);
        final TextView tvCategoryName = (TextView) MainView.findViewById(R.id.tvCategoryName);
        final TextView tvAddDate = (TextView) MainView.findViewById(R.id.tvAddDate);
        final TextView tvDataValue = (TextView) MainView.findViewById(R.id.tvDataValue);
        final Button btnDeleteCategory = (Button) MainView.findViewById(R.id.btnDeleteCategory);

        tvCategoryName.setText(Item.getCategory());
        tvAddDate.setText(Item.getAddDate());
        tvDataValue.setText(Item.getDataValue());

        if(Item.getCompleted().equals("YES")){
            cbCompleted.setChecked(true);

            tvCategoryName.setEnabled(false);
            tvAddDate.setEnabled(false);
            tvDataValue.setEnabled(false);
        } else {
            cbCompleted.setChecked(false);

            tvCategoryName.setEnabled(true);
            tvAddDate.setEnabled(true);
            tvDataValue.setEnabled(true);
        }

        cbCompleted.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    CategoryUpdate(Item.getID(),"Completed","YES");

                    tvCategoryName.setEnabled(false);
                    tvAddDate.setEnabled(false);
                    tvDataValue.setEnabled(false);
                } else {
                    CategoryUpdate(Item.getID(),"Completed","NO");

                    tvCategoryName.setEnabled(true);
                    tvAddDate.setEnabled(true);
                    tvDataValue.setEnabled(true);
                }
            }
        });

        btnDeleteCategory.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                TaskList Process = new TaskList();
                Process.Delete(btnDeleteCategory, Item.getID());
            }
        });
    }

    return MainView;
}

public boolean CategoryUpdate(String ID, String Key, String Value){
    boolean Result;

    try{
        SQLiteDatabase Database = DatabaseActivity.getWritableDatabase();

        ContentValues Values = new ContentValues();

        Values.put(Key, Value);

        Database.update("Category", Values, "ID = " + ID, null);

        Result = true;
    } catch (SQLiteException Error) {
        Toast.makeText(ActivityContext, "Error (CategoryUpdate) : " + Error.toString(), Toast.LENGTH_LONG).show();

        Result = false;
    }

    return Result;
}

public void CategoryDelete(final String ID){
    try{

        AlertDialog.Builder Builder = new AlertDialog.Builder(ActivityContext);
        Builder.setMessage("If you delete this category, category's tasks will be deleted ! Do you want to delete this category ?")
                .setCancelable(false)
                .setPositiveButton("YES",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                SQLiteDatabase Database = DatabaseActivity.getWritableDatabase();

                                Database.delete("Category", "ID = " + ID, null);
                            }
                        })
                .setNegativeButton("NO",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.cancel();
                            }
                        });
        AlertDialog Alert = Builder.create();
        Alert.show();
    } catch (SQLiteException Error) {
        Toast.makeText(ActivityContext, "Error (CategoryDelete) : " + Error.toString(), Toast.LENGTH_LONG).show();
    }
}

}

This is my DatabaseClass (TaskListDatabase.java)

package com.nano.tasklist;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TaskListDatabase extends SQLiteOpenHelper{

private static final String DatabaseName = "TaskList";
private static final int DatabaseVersion = 1;
private static final String Category = "Category";
private static final String Tasks = "Tasks";

private static final String CreateCategoryTable = "CREATE TABLE " + Category + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, Category TEXT, AddDate TEXT, Completed TEXT);";
private static final String CreateTaskTable = "CREATE TABLE " + Tasks + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, Category TEXT, Task TEXT, AddDate TEXT, StartDate TEXT, FinishDate TEXT, Completed TEXT);";

public TaskListDatabase(Context Context){
    super(Context,DatabaseName,null,DatabaseVersion);
}

@Override
public void onCreate(SQLiteDatabase Database) {
    Database.execSQL(CreateCategoryTable);
    Database.execSQL(CreateTaskTable);
}

@Override
public void onUpgrade(SQLiteDatabase Database, int OldVersion, int NewVersion) {
    Database.execSQL("DROP TABLE IF EXISTS " + DatabaseName);
    onCreate(Database);
}
}

And this is my project : https://rapidshare.com/files/578334898/Task%20List.rar

Please help me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:01:11+00:00Added an answer on June 13, 2026 at 1:01 pm

    You are doing this for delete record.

    btnDeleteCategory.setOnClickListener(new OnClickListener(){
                public void onClick(View v) {
                    TaskList Process = new TaskList();
                    Process.Delete(btnDeleteCategory, Item.getID());
                }
            });
    

    Your Mistake.

    1)TaskList is your launcher Activity and I can't find any Delete() method in this class and call it in listener.
    2)May be some code of query for delete in this method Delete()
    3)You didn't refresh list using `categoryAdapter.notifyDataSetChanged();`
    

    Solution:

    1)Make method for delete(delete query) in `TaskListDatabase.java`
    2)You display data from `ArrayList<CategoryInfo> Items;` so You also remove that data from this ArrayList.
    3)Use `categoryAdapter.notifyDataSetChanged();` for refresh list
    

    Try this code…

    btnDeleteCategory.setOnClickListener(new OnClickListener(){
                public void onClick(View v) {
                    TaskListDatabase db = new TaskListDatabase();
                    db.delete();
                    Items.remove(position);
                    notifyDataSetChanged();
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have an Android project that has a database with two tables: tbl_question
Have a quick question. I am using a SQLite database file in my C#
Have just finished a couple of tutorials regarding populating a SQLite database with data
I'm new to android apps development and I have a basic sqlite question. What
I have question i.e how can i select a previous div CODE:- if($i >
I have a small database which is legacy from an almost defunct project. This
I have an app that uses a SQLite database. When the app updates at
I am using SQlite as a database in a C# winforms application. My project
I've just got my first SQLite database up and running but to reproduce it
I have recently inherited a large project using an sqlite3 database and currently I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.