I have an activity which has two edit text fields: one for the title and the other for the story.
The entries made two text fields are saved in the database, also the database has a ROW_ID
,TITLE_ID
and STORY_ID
. The entries are displayed in a list view.
When an item is long clicked, I get the row id corresponding to that item.
How should I get the TITLE_ID
and STORY_ID
from this?
Asked
Active
Viewed 123 times
-2

Swati Garg
- 995
- 1
- 10
- 21

user47
- 395
- 1
- 2
- 16
-
2Please post the relevant code and any logcat errors. – Sam May 24 '12 at 18:58
-
Learning some basic SQL would help your situation. – JoxTraex May 24 '12 at 20:20
2 Answers
1
You could query the data base for the TITLE_ID and STORY_ID that correspond to the ROW_ID.
Post what code you have and we will be able to give more specific answers.

cstrutton
- 5,667
- 3
- 25
- 32
1
Say, you have the corresponing row id of item which is long clicked in a variable rid. Then run the following query:
String q = "SELECT * FROM TABLE_NAME where(ROW_ID like '"+rid+"')";
Cursor c = db.rawQuery(q, null); // db is a object of SQLiteDatabase type
Then retrieve TITLE_ID and STORY_ID like:
if(c.getCount() == 0)
{
//No entry found
}
else {
c.moveToFirst();
do {
String titleid = c.getString(c.getColumnIndex("TITLE_ID"));
String storyid = c.getString(c.getColumnIndex("STORY_ID"));
} while (c.moveToNext());
c.close();
Then use them as you like :)

Imran Rana
- 11,899
- 7
- 45
- 51
-
There is no reason for a raw query. Using the standard sqlite database interaction of .query() is more than enough. Also its less prone to errors. – JoxTraex May 24 '12 at 20:22
-
@JoxTraex after lots of googling and going through developer site I was unable to find any perforformance draback of **rawQuery** in comparison with **query()**. Their only difference is with the structure. **query()** needs you to enter different parts of the statement in segments and separate them with commas but statement in **rawQuery** is much easier for a beginner to understand. Should I get a downvote for this? – Imran Rana May 25 '12 at 04:04
-
Basically the rule is.. if its simpler, its less error prone. Your answer is still right, but your approach to use a raw query for something so simple is overkill. – JoxTraex May 25 '12 at 04:39
-
@JoxTraex in my humble opinion if there is no performance difference between **rawQuery** and **query** then how can the use of **rawQuery** be a overkill for this simple case? – Imran Rana May 25 '12 at 04:46
-
its merely the fact that is is more error prone instead of using the simplified classes that were provided by google, if you dont NEED to do a raw query, dont. – JoxTraex May 25 '12 at 04:57
-