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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:58:36+00:00 2026-06-04T09:58:36+00:00

I have a XML layout which has two edit text fields, one for title

  • 0

I have a XML layout which has two edit text fields, one for “title” and the the other for “story”,when the user enters his data in these text fields, and presses the back button , the entry gets saved in a list view as the title set.The list view is present in an activity say A1. Now A1 extends Activity. Also ,whenever an item in the list is “long clicked” a context menu appears, which has edit, delete and read buttons. Now if edit button is pressed I need to open another activity which can edit the data entered in the text fields corresponding to the item clicked, Also I’d be needing the id and the position of the item clicked in the list. I am using list variable of type ListView to add my adapter.Also I am checking the edit,delete and read options of the context menu in the ” public boolean onContextItemSelected(MenuItem item) ” procedure, How can I get the id and the position of the item clicked in the edit, read and delete options of the context menu?

here’s some piece of code of activity A1:
”
static id_item_clicked;

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // here arg3 is the id of the item which is pressed
    registerForContextMenu(arg1);
    final long row_passed = arg3;
    Cursor c = (Cursor) arg0.getItemAtPosition(arg2);
    title = c.getString(c.getColumnIndex(DataHolder.KEY_TITLE));
    story = c.getString(c.getColumnIndex(DataHolder.KEY_STORY));
            ........

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    // TODO Auto-generated method stub
    id_item_clicked = arg3;
    return false;
}


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

@Override
public boolean onContextItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    if (item.getTitle() == "EDIT") {

        int position = list.getSelectedItemPosition();
        long item_id = list.getSelectedItemId();


    }
    if (item.getTitle() == "READ") {

    }
    if (item.getTitle() == "DELETE") {

    }
    return super.onContextItemSelected(item);
} "
  • 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-04T09:58:37+00:00Added an answer on June 4, 2026 at 9:58 am

    You need to get the context menu info using AdapterContextMenuInfo, then info.id will give you the row id:

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        long rowid = info.id    // This is your row id
        // Your code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this main.xml layout which has a fixed header and footer. The body
In my application i have an activity which has the following layout <?xml version=1.0
Context: I have a TableLayout (created using XML), which has one TableRow, which has
I have an xml layout which I use for each row in my listview:
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
I have added an easy compound control which loads its layout from a XML
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have a Relative Layout. Which has 2 buttons, side by side and it
I have a layout xml file named my_layout.xml, in which the root view's layout_width
I have a Flex3 project with 2 HorizontalList controls; one of which has drag

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.