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 8788275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:06:50+00:00 2026-06-13T22:06:50+00:00

how can i delete data in database when i click an item in listview?

  • 0

how can i delete data in database when i click an item in listview? please give me some code to that.
this my method to choose item in listview:

listview.setOnItemClickListener(new OnItemClickListener(){
        public void onItemClick(AdapterView adapterView, View convertView, int position, long id)
        {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(AndroidSpinnerFromSQLiteActivity.this);


            alertDialog.setTitle("Confirm Delete...");


            alertDialog.setMessage("Are you sure you want delete this?");


            alertDialog.setIcon(R.drawable.delete);


            alertDialog.setPositiveButton("YES",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int which) {


                        }
                    });

            alertDialog.setNegativeButton("NO",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });

            alertDialog.show();
            }
        });
    };

this my database class:

public class DatabaseHandler extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;


private static final String DATABASE_NAME = "spinnerExample";


private static final String TABLE_LABELS = "labels";


private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {

    String CREATE_CATEGORIES_TABLE = "CREATE TABLE " + TABLE_LABELS + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT" +")";
    db.execSQL(CREATE_CATEGORIES_TABLE);
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS);


    onCreate(db);
}


public void insertLabel(String label){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, label);


    db.insert(TABLE_LABELS, null, values);
    db.close(); 
}


public List<String> getAllLabels(){
    List<String> labels = new ArrayList<String>();


    String selectQuery = "SELECT  * FROM " + TABLE_LABELS;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);


    if (cursor.moveToFirst()) {
        do {
            labels.add(cursor.getString(1));
        } while (cursor.moveToNext());
    }


    cursor.close();
    db.close();


    return labels;
}

}

  • 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-13T22:06:51+00:00Added an answer on June 13, 2026 at 10:06 pm

    Add one method in ur database class code

    if u want to Delete Table All Raw then use

    db.execSQL("DELETE from "+Table_Name);
    

    other u want to deleted particular Raw in table

     db.delete(Table_Name, "Raw_Field_Name" + "='" + Raw_field_value+"'", null);
    

    list view item click event use

        Listview lv;
    //on create method 
    
         lv = (ListView) findViewById(R.id.list_contact_name);
    
                  lv.setOnItemClickListener(new OnItemClickListener() 
                    {
    
                        public void onItemClick(AdapterView<?> arg0, View v, int position,
                                long id) {
    
                          // call DELETE method here
    
                        }
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How I can delete an object which I had added before with this code.
I am developing UI form that has infragistics grid. Users can delete, submit some
I'm Having some trouble deleting an entry on my database. I can insert data,
How can i delete a html-special char \ from a string. $string = 'This
I have a foreach that prints the data from my database in PHP. I
I'm displaying tabular data populated via loop from a database. I know that I
I have a Listview and a button like this Below is the code I
Each row in the data table has a delete button. On click of the
I found some fantastic code that meets the needs for my project from here:
I'm trying to build a system where I can submit data to a database

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.