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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:05:40+00:00 2026-06-01T13:05:40+00:00

I’m trying to pass the item clicked to another activity i.e from A to

  • 0

I’m trying to pass the item clicked to another activity i.e from A to B using a custom itemsAdapter with sqlite.

How can I achieve the following?

1)Get the item clicked position using cursor
2)Pass the item clicked to another activity

I’m trying to do similar to this example but use my own custom adapter
I have dome the following so far.

Activity A:

public void onListItemClick(ListView parent, View view, int position, long id) {
Intent intent = new Intent(this,F32Activity.class);
Cursor cursor = (Cursor) itemsAdapter.getItem(position);
intent.putExtra("PROPERTY_ID", cursor.getInt(cursor.getColumnIndex("_id")));

startActivity(intent);
return;
 }

Activity B:

      propertyId = getIntent().getIntExtra("PROPERTY_ID", 0);
    System.out.println(employeeId);
    SQLiteDatabase db = (new Helper(this)).getWritableDatabase();
    Cursor cursor = db
            .rawQuery("SELECT * from my_table WHERE pro._id = ?",
                    new String[] { "" + propertyId });

Added the Adapter

private void getItemId(int position) {
    // TODO Auto-generated method stub

}

private void getDataAndPopulate() {
    // TODO Auto-generated method stub
    image = new ArrayList<byte[]>();       
    bedrooms= new ArrayList<String>();
    address= new ArrayList<String>();
    propType= new ArrayList<String>();

    Cursor cursor = getEvents(" gall,properties where  properties._id = gall._id  " );

    while (cursor.moveToNext()) {
        //String temp_id = cursor.getString(0);
        byte[] temp_image = cursor.getBlob(2);
        String temp_identifier = cursor.getString(1);
        String temp_price = cursor.getString(3);
        String temp_bedrooms = cursor.getString(4);
        String temp_address = cursor.getString(5);
        String temp_propType = cursor.getString(6);


        image.add(temp_image);
        //System.out.println(image);

        bedrooms.add(temp_bedrooms);
        address.add(temp_address);
        propType.add(temp_propType);


}
    String[] identifierArray = (String[]) bedrooms.toArray(new String[bedrooms
                                                                    .size()]);
   itemsAdapter = new ItemsAdapter(PropertyResult.this,
   cursor, R.layout.activity_f9, identifierArray);
   setListAdapter(itemsAdapter);

}

private class ItemsAdapter extends BaseAdapter {
    String[] items;

    public ItemsAdapter(Context context, Cursor cursor,int textViewResourceId,
            String[] items) {
        this.items = items;
    }

    public View getView(final int POSITION, View convertView,
            ViewGroup parent) {
        TextView desc;
        TextView cap;
        TextView ident;
        TextView pric;
        TextView bedroom;
        TextView addres;
        TextView propertytyp;
        View view = convertView;
        ImageView img;
        if (view == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.activity_f9, null);

        }
        img = (ImageView) view.findViewById(R.id.image);        

        bedroom = (TextView) view.findViewById(R.id.bedrooms);
        addres = (TextView) view.findViewById(R.id.address);
        propertytyp = (TextView) view.findViewById(R.id.propertytype);          


        bedroom.setText("£"+bedrooms.get(POSITION));
        addres.setText(address.get(POSITION));
        propertytyp.setText(propType.get(POSITION));

        img.setImageBitmap(BitmapFactory.decodeByteArray(
        image.get(POSITION), 0, image.get(POSITION).length));

        return view;

    }

    public int getCount() {
        return items.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
}

Please kindly give me a solution.

  • 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-01T13:05:41+00:00Added an answer on June 1, 2026 at 1:05 pm

    In the onListItemClick() you already have the row id from the cursor, is the 4th parameter, id(this only works for cursor adapters).

    First of all also create and ArrayList that will hold long values(the row ids from the cursor):

    ids = new ArrayList<Long>();
    //...
    while (cursor.moveToNext()) {
       String temp_id = cursor.getString(0);// if 0 is your column containing the id(check it)
       ids.add(temp_id);
       //...
    }
    

    Then in your adapter override the method getItemId and return the long values from the ids ArrayList according to the position supplied:

       public long getItemId(int position) {
            return ids.get(position);
        }
    

    Then in your onListItemClick() simply use the id parameter:

    public void onListItemClick(ListView parent, View view, int position, long id) {
       Intent intent = new Intent(this,F32Activity.class);
       intent.putExtra("PROPERTY_ID", id);
       startActivity(intent);
    }
    

    Then in the receiving activity:

    propertyId = getIntent().getLongExtra("PROPERTY_ID", 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.