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.

4

2 回答 2

0

您可以将您的图像位置传递给您的下一个活动......然后将该图像位置传递给您的选择查询,从中将显示该图像的相关数据......

所以试试这个:

String sqlString ="SELECT * FROM Heroes where id = "+position;
于 2013-08-26T11:34:42.850 回答
0

尝试这个::

给你的图片标签加上行的ID。如果你有10张图片,那么你必须给图片标签

imageView.SetTag(行 ID); //行号,对所有行都是唯一的。

现在,当您单击图像时,将该图像的标签传递给意图。并在接收意图时获取标签并将查询触发到 sql 以获取该特定行 id 的数据,例如:

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

希望能帮助到你!!

于 2013-08-26T11:25:00.087 回答