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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:34:57+00:00 2026-06-16T16:34:57+00:00

I already use Context Menu in my ListActivity.java, but the Context Menu is not

  • 0

I already use Context Menu in my “ListActivity.java”, but the Context Menu is not open and pop up. I add two options in Context Menu first for Show Record, and other for Delete Record. When i Long Pressed on ListView record then Context Menu is Open and i choose “Show” then particular record is display on other activity. In this activity, i create form. The record is adjusted in this form field. So how can i do this???

**My ListActivity.java is here:**

public class ListActivity extends Activity {
    ListView lv;
    ArrayList<String> items = new ArrayList<String>();
    ArrayList<String> items_id = new ArrayList<String>();
    dbhelper dh;
    SQLiteDatabase db;
    int index_id;
    Button btn;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        Button btn;
        btn = (Button)findViewById(R.id.newProjectlist);
        btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub


                    Intent intent= new Intent(ListActivity.this,NewProject.class);
                startActivity(intent);
            }
        });  
        lv = (ListView)findViewById(R.id.projectListView);
        setUpList();
        dh = new dbhelper(this);

        Cursor c = getAllData();
        showAllData(c);  
        registerForContextMenu(lv);      
    }

  @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        // TODO Auto-generated method stub
        super.onCreateContextMenu(menu, v, menuInfo);

        if(v.getId() == R.id.projectList){
            menu.setHeaderIcon(R.drawable.ic_launcher);
            menu.setHeaderTitle("Record List");
            menu.add(0,1,menu.NONE,"Delete Record");
            menu.add(0,2,menu.NONE,"Show Record");
        }
    }

    @Override
public boolean onContextItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
        int itemId = item.getItemId();
        if(itemId == 1)
        {
            AdapterView.AdapterContextMenuInfo menuinfo = (AdapterContextMenuInfo) item.getMenuInfo();
            int poistion = menuinfo.position;
            String id_string = items_id.get(poistion);
            long id = Long.valueOf(id_string);

            //menuinfo = (AdapterContextMenuInfo) item.getMenuInfo();
            //index_id = menuinfo.position;
            deleteUserData(index_id);
            items_id.remove(poistion);
        }
        if(itemId == 2){
            AdapterView.AdapterContextMenuInfo menuinfo;
            menuinfo = (AdapterContextMenuInfo) item.getMenuInfo();
            index_id = menuinfo.position;
            editUserData(index_id);
        }
    return super.onContextItemSelected(item);
}

    private void editUserData(int indexid) {
        // TODO Auto-generated method stub
        String user_id = items_id.get(indexid);
        Intent intEdit = new Intent(ListActivity.this, MainActivity.class);
        intEdit.putExtra("EditID", user_id);
        startActivityForResult(intEdit, 1);
    }

    private void deleteUserData(int indexid) {
        // TODO Auto-generated method stub
//      String user_id = items_id.get(indexid);
        //Toast.makeText(getApplicationContext(), "id " + user_id, 1).show();
        db = dh.getWritableDatabase();
        db.delete("timer","_ID" + "=" + indexid, null);
        finish();
//      Toast.makeText(getApplicationContext(), "Record deleted successfully", 1).show();
    }

    private void showAllData(Cursor c) {
        // TODO Auto-generated method stub
        while(c.moveToNext())
        {
            int id = c.getInt(0);
            String name = c.getString(1);
            String timerpoint1 = c.getString(2);
            String timerpoint2 = c.getString(3);
            String timerpoint3 = c.getString(4);
            String servicetime1 = c.getString(5);
            String servicetime2 = c.getString(6);
            items.add("" + name);
            items_id.add(""+id);
        }
        setUpList();
    }

    private Cursor getAllData() {
        // TODO Auto-generated method stub
        db = dh.getReadableDatabase();
        //String sortorder = dh.Name + "DESC";
    //  String query ="SELECT DISTINCT name FROM timer";
    //  Cursor c = db.rawQuery(query, null);
    //   if (c != null) {
    //            c.moveToFirst();
    //        }
//      String[] cols = new String[] {"name"};
        Cursor c = db.query(true, "timer",null,null,null,null,null,null,null);   
        //Cursor cur = db.query(Distinct,"timer", null, null, null, null, null, null, null);
        startManagingCursor(c);
    //  Cursor c=db.rawQuery("select distinct Name from timer;",null);
        return c;   
        }     
    private void setUpList() {
        // TODO Auto-generated method stub
        lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,items));
    }   

    }
  • 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-16T16:34:58+00:00Added an answer on June 16, 2026 at 4:34 pm

    You should be able to delete a row with:

    if(itemId == 1)
    {
        AdapterView.AdapterContextMenuInfo menuinfo = (AdapterContextMenuInfo) item.getMenuInfo();
        deleteUserData(menuInfo.id);
        items_id.remove(menuInfo.position);
    }
    

    And if you use a CursorAdapter to bind your database information to your ListView you shouldn’t need to call remove(), it’ll be done automatically through the built-in DataObserver.

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

Sidebar

Related Questions

I already know that most implementations use a single thread, but is there anything
In my application I already use ResourceBundleMessageSource <bean id=messageSource class=org.springframework.context.support.ResourceBundleMessageSource p:basename=i18n/messages /> And all
I wish to know which are the Eclipse navigation keyboard shortcuts. I already use:
Is anybody using OpenGLES2.0 shaders (GLSL) successfully for audio synthesis? I already use vDSP
I am a Symfony developer and my web server is Linux. I already use
I am looking to implement a grid system. I already use jQuery, jQuery UI
I am developing a web database that is already in use for about a
Is there a GWT Date Time Component? Note: I am already making use of
Is there anyone who has already tried to use the Microsoft Bing translator web
I use a CursorLoader in a LoaderManager with a Custom CursorAdapter. I've already achieved

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.