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

  • SEARCH
  • Home
  • 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 7655053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:24:51+00:00 2026-05-31T12:24:51+00:00

Possible Duplicate: how to delete item from listView? I fetch data from Database in

  • 0

Possible Duplicate:
how to delete item from listView?

I fetch data from Database in listview and it display properly but I need to delete
item from listview and database by clicking on it and I don’t have any idea about that.
Here is my sample code, please give me suggestion or hint.

public class MyTable extends ListActivity {

private ArrayList<String> results = new ArrayList<String>();
int counter=0;

 MySQLiteHelper m=new MySQLiteHelper(this);
@Override
protected void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);     
     retriveData();         
     displayResultList();        
}   
private void displayResultList() {
    TextView tView = new TextView(this);
    tView.setText("Loc Wise Profile! if you want to delete  " +
            "just click on the Profile!");
    tView.setTextColor(Color.YELLOW);
    getListView().addHeaderView(tView);

    setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, results));
    getListView().setTextFilterEnabled(true);       
}
private void retriveData() {
    try {
        final MySQLiteHelper m=new MySQLiteHelper(getBaseContext());
        final List<LocWiseProfileBeans> LocWiseProfile= m.getAllLocWiseProfile();       

        for (final LocWiseProfileBeans cn : LocWiseProfile)
        {

                    results.add(cn.getLocname() + " " + cn.getSelectedprofile());
        }                       
    } catch (Exception e ) {            
    } 

}   

MySQliteHelper.java

public class MySQLiteHelper extends SQLiteOpenHelper {

public static final String TABLE_NAME = "loc_wise_profile";
public static final String TABLE_NAME2 = "supervisor";
public static final String COLUMN_ID = "_id";
public static final String COLUMN1 = "loc_name";
public static final String COLUMN2 = "lattitude";
public static final String COLUMN3 = "longitude";
public static final String COLUMN4 = "selectedprofile";
public static final String COLUMN5 = "contactno";
public static final String COLUMN6 = "message";
//public static final String COLUMN7 = "enabled";
public static final String COLUMN8 = "NotificeationMessage";

SQLiteDatabase db;   
private static final String DATABASE_NAME = "locale";
private static final int DATABASE_VERSION = 2;

// Database creation sql statement
private static final String DATABASE_CREATE = "create table IF NOT EXISTS "
        + TABLE_NAME + "( " + COLUMN_ID
        + " integer primary key autoincrement, " 
        + COLUMN1 + " text not null, "
        + COLUMN2 + " double not null, "
        + COLUMN3 + " double not null, "
        + COLUMN4 + " text not null ,"
        + COLUMN5 + " text not null ,"
        + COLUMN6 + " text not null ,"
        //+ COLUMN7 + " text not null ,"
        + COLUMN8 + " text not null "
        + ");";



public MySQLiteHelper(Context context)
{
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase database) {
    // TODO Auto-generated method stub
    database.execSQL(DATABASE_CREATE);
    //database.execSQL(DATABASE_CREATE2);
}


  // Adding new Location wise Profile
public void insertLocWiseProfile(LocWiseProfileBeans loc) {
     db= this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(COLUMN1, loc.getLocname()); // Contact Name
    values.put(COLUMN2, loc.getLattitude()); // Contact Phone Number
    values.put(COLUMN3, loc.getLongitude());
    values.put(COLUMN4, loc.getSelectedprofile());
    values.put(COLUMN5, loc.getContactno());
    values.put(COLUMN6, loc.getMessage());
    //values.put(COLUMN7, loc.getEnabled());
    values.put(COLUMN8, loc.getNotificationMessage());
    // Inserting Row
    db.insert(TABLE_NAME, null, values);
    db.close(); // Closing database connection
}


    // Getting All Contacts
 public List<LocWiseProfileBeans> getAllLocWiseProfile() {
    List<LocWiseProfileBeans> LocWiseProfileList = new ArrayList<LocWiseProfileBeans>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_NAME;

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

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            LocWiseProfileBeans loc= new LocWiseProfileBeans();
            //loc.set
            loc.setId(cursor.getInt(0));
            loc.setLocname(cursor.getString(1));
            loc.setLattitude(cursor.getDouble(2));
            loc.setLongitude(cursor.getDouble(3));
            loc.setSelectedprofile(cursor.getString(4));
            loc.setContactno(cursor.getString(5));
            loc.setMessage(cursor.getString(6));
           // loc.setEnabled(cursor.getString(7));
            // Adding contact to list
            LocWiseProfileList.add(loc);
        } while (cursor.moveToNext());
    }

    // return contact list
    return LocWiseProfileList;
}


@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    Log.w(MySQLiteHelper.class.getName(), "Upgrading database from version "
            + oldVersion + " to " + newVersion
            + ", which will destroy all old data");
    database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(database);
}
public void delete(int value)
{
    try{            
        SQLiteDatabase db= this.getWritableDatabase();
        db.delete(TABLE_NAME, COLUMN_ID+"="+value, null);

}
    catch(Exception e){}

}


public void deleteAll(){
    try{
    //db.execSQL("delete * from "+ TABLE_NAME);

        SQLiteDatabase db= this.getWritableDatabase();
        db.delete(TABLE_NAME, null, null);

    }catch(Exception e){}
}

public void deleteNyName(String string)
{
    // TODO Auto-generated method stub
    SQLiteDatabase db= this.getWritableDatabase();
       db.delete(TABLE_NAME, COLUMN1 +"=?", new String [] { COLUMN1 });
       db.close();
}   

}

  • 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-05-31T12:24:52+00:00Added an answer on May 31, 2026 at 12:24 pm

    I have used this as in my code like in this

    See this link http://typicaljava.blogspot.in/2011/12/add-element-in-list-and-remove-it-by.html

    OnItemClickListner call your delete query and update the list in it instead of the Array which i have used.

    This might be useful to you..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What's the best way to delete all data from a table? Clear
Possible Duplicate: How to delete an element from an array in php? For instance,
Possible Duplicate: MySQL delete row from multiple tables I have 5 tables: members member_videos
Possible Duplicate: Android ListView with delete button android Listview button Okay .. I will
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I
Possible Duplicate: How to delete duplicate records in mysql database? there are duplicate rows
Possible Duplicate: What to do when I want to use database constraints but only
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: How to delete an element from an array in php? I have
Possible Duplicate: select multiple rows from uitableview and delete I am developing an application

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.