Get custom itemsAdapter id using cursor android

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")));


Activity B:

      propertyId = getIntent().getIntExtra("PROPERTY_ID", 0);
    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);



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


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(;        

        bedroom = (TextView) view.findViewById(;
        addres = (TextView) view.findViewById(;
        propertytyp = (TextView) view.findViewById(;          


        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.


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)

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);

Then in the receiving activity:

propertyId = getIntent().getLongExtra("PROPERTY_ID", 0);

Your on Item should like this

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {

    String strEventName, strEventDate;
    int Id;
    Cursor c = (Cursor) arg0.getAdapter().getItem(position);
    intent.putExtra("PROPERTY_ID", cursor.getInt(cursor.getColumnIndex("_id")));

Need Your Help

ERROR 1 (HY000): Can't create/write to file on windows server 2008

mysql window

i am using mysql 5.1.34 and windows server 2008 when i try to out a csv using a procedure on mapped network drive in mysql it is showing this error (ERROR 1 (HY000): Can't create/write to file on w...

universal windows app , making a WebRequest Method = GET

c# windows windows-10

Does anyone know how to get the WebResponse ?? the method GetResponse() is obsolet, btw it's windows universal app.