0

I have been trying to find something that can help me to retrieve SQLite database row when I click on the gridview image ! Like when I click the first image on the new activity it shows me some data related to that image which is saved in the database.

@Override
public void onClick(View v) {
  // TODO Auto-generated method stub
  Intent intent = new Intent(mContext,HeroData.class);
  intent.putExtra("imageID", mThumbIds[position]);
  mContext.startActivity(intent);
}

This is how I'm starting a new activity and putting the image which I click, now I need to know how to get a SQL database row which has some data related to that image.

public Cursor getTestData() 
 { 
     try 
     { 
         String sql ="SELECT * FROM Heroes"; 

         Cursor mCur = mDb.rawQuery(sql, null); 
         if (mCur!=null) 
         { 
            mCur.moveToNext(); 
         } 
         return mCur; 
     } 
     catch (SQLException mSQLException)  
     { 
         Log.e(TAG, "getTestData >>"+ mSQLException.toString()); 
         throw mSQLException; 
     } 
 }

the above is the cursor to get all data, but i want only one row.

Mohsin Mushtaq
  • 133
  • 1
  • 5
  • 17

2 Answers2

0

Try this::

Give your image tag with the ID of row.if you have 10 images then you have to give tag to image like

imageView.SetTag(ID of Row); //Row No which is unique for all rows.

Now when you click on Image pass the tag of that image to intent. and on receive intent get the tag and fire the query to sql to get data for that particular row id like:

String sql ="SELECT * FROM Heroes where ID = "+TagID;

Hope it Helps!!

Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24
0

You can pass a your Image Position to your next Activity... And after that Pass that image Position to your Select Query from where related data of that image will be displayed...

So try this:

String sqlString ="SELECT * FROM Heroes where id = "+position;
Piyush
  • 18,895
  • 5
  • 32
  • 63