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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:54:05+00:00 2026-05-30T20:54:05+00:00

I am trying to get the primary key _id from the selected group using

  • 0

I am trying to get the primary key “_id” from the selected group using code

groupPositionID is a global variable initialized like this
and IngredientListGroup_cursor is a group cursor which fetches the group data for expanable list view.

String groupPositionID=null;
Cursor IngredientListGroup_cursor;

in the oncreate code:

public void onCreate(Bundle savedInstanceState) {
IngredientListGroup_cursor=helper.GetIngredientsList();
}

ExpandableIngredietnsList.setOnGroupClickListener(new OnGroupClickListener(){

                @Override
                public boolean onGroupClick(
                        ExpandableListView paramExpandableListView,
                        View paramView, int paramInt, long paramLong) {
                    // TODO Auto-generated method stub

                    groupPositionID=IngredientListGroup_cursor.getString(0);

                    Toast toast = Toast.makeText(getBaseContext(),groupPositionID ,Toast.LENGTH_LONG);       
                    toast.show();
                    return false;
                }

            });

this is my SQLhelper function for deleting the selected group from database.

public Cursor GetIngredientsList(){

    return(getReadableDatabase().rawQuery("SELECT _id,Ingredient_name FROM tblIngredients",null));

}

public Cursor DeleteIngredientsList_Item(String index){
        String[] args={index};
        return(getReadableDatabase().rawQuery("DELETE FROM tblIngredients WHERE _id=?",args));

}

The problem I am facing is tha although i am getting the id for the selected group from cursor (i m able to see that as toast) but then, why i am not able to delete that from context menu.

on selecting delete from context menu the following code should execute properly

public boolean onOptionsItemSelected(MenuItem IngredientItem){
    if(IngredientItem.getItemId()==R.id.addIngredient){
        Intent i= new Intent(Ingredients_List.this,Ingredients_Add.class);
        startActivity(i);
        return(true);
    }
    else if (IngredientItem.getItemId()==R.id.deleteIngredient) {

        if(groupPositionID!=null){
              helper.DeleteIngredientsList_Item(groupPositionID);
              return(true);
            }
            else{
                Toast.makeText(getBaseContext(), "Select The Ingredient You want to delete", Toast.LENGTH_LONG).show(); 
            }
    }
    return (super.onOptionsItemSelected(IngredientItem));

} 

I am getting the selected primary key id value from “groupPositionID” variable here.. accurate value is transferred to database raw query also… still not getting what i am expecting

Plz help ASAP I am new to both android and java

sdk information(although not required)

android:versionCode="1"
android:versionName="1.0" 
android:minSdkVersion="8"

Thanks in Advance

  • 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-30T20:54:07+00:00Added an answer on May 30, 2026 at 8:54 pm
    public void DeleteIngredientsList_Item(long index){
    
        String[] args = new String[]{Long.toString(index)};
        Log.v("I am in", "SQLHelper");
        getWritableDatabase().execSQL("DELETE FROM tblIngredients WHERE _id=?",args);
    
    }
    

    i modified this delete code in mysql helper

    my function was earlier returning cursor thats why it was not working … meanz in actual query was not getting executed…

    rest was ok.. 🙂

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

Sidebar

Related Questions

I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
Using: SQL Server Database: Northwind I'd like to drop a table primary key, without
Trying to get my css / C# functions to look like this: body {
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying to get all duplicate rows from a DB. Lets say I have
I am trying to implement Bidirectional Mapping with Fluent NHibernate Mapping. Code snippet from
I am using Spring MVC 2.5, and I am trying to get a JSTL
i trying to retrieve value by referencing primary key in multiple tables but unable

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.