this is my language table
/*
* initialValues in Languages(
* KEY_LANG_ID,
* KEY_LANG, \\ language name
* KEY_ACT) \\ 0= not active, 1= active
*/
ContentValues initialValues3 = new ContentValues();
initialValues3.put(KEY_LANG, "English");
initialValues3.put(KEY_ACT, "1");
db.insert(LANGS_TABLE, null, initialValues3);
initialValues3.put(KEY_LANG, "German");
initialValues3.put(KEY_ACT, "1");
db.insert(LANGS_TABLE, null, initialValues3);
initialValues3.put(KEY_LANG, "Spain");
initialValues3.put(KEY_ACT, "0");
db.insert(LANGS_TABLE, null, initialValues3);
initialValues3.put(KEY_LANG, "Italy");
initialValues3.put(KEY_ACT, "0");
db.insert(LANGS_TABLE, null, initialValues3);
initialValues3.put(KEY_LANG, "China");
initialValues3.put(KEY_ACT, "0");
db.insert(LANGS_TABLE, null, initialValues3);
this is my sentences table
/*initialValues in Sentences(
* KEY_SEN_ID,
* KEY_SEN_ID_TH_SEN,
* KEY_SEN_ID_LANG,
* KEY_SEN,
* KEY_SEN_READING,
* KEY_ACT_VOL)
* */
I want to show sentences in my list view and sentence must check KEY_ACT from language table if KEY_ACT =1 then sentence show from above in list view must only have English and German sentence so I try to query like this
public Cursor getSen_List(long id_t开发者_Python百科hsen ) {
String strTmp = "select "
+SENS_TABLE+"."+KEY_SEN_ID+","
+SENS_TABLE+"."+KEY_SEN_ID_TH_SEN+","
+SENS_TABLE+"."+KEY_SEN_ID_LANG+","
+SENS_TABLE+"."+KEY_SEN+","
+SENS_TABLE+"."+KEY_SEN_READING+","
+SENS_TABLE+"."+KEY_ACT_VOL+","
+LANGS_TABLE+"."+KEY_LANG
+" from "+SENS_TABLE+ ","+LANGS_TABLE
+" where "+SENS_TABLE+"."+KEY_SEN_ID_TH_SEN + "=" + id_thsen+ " and "
+SENS_TABLE+"."+KEY_LANG_ID+"=(select "
+LANGS_TABLE+"."+KEY_LANG_ID
+" from "+LANGS_TABLE
+" where "+LANGS_TABLE+"."+KEY_ACT+"=1)";
return db.rawQuery(strTmp,null);
}
but the result is show only same English sentence for 5 time
Does anybody have any idea?
please help.....
I've not used ContentValues
before, but it looks like since you are reusing the same object over and over again, you keep re-inserting the same values:
ContentValues initialValues3 = new ContentValues();
initialValues3.put(KEY_LANG, "English");
initialValues3.put(KEY_ACT, "1");
db.insert(LANGS_TABLE, null, initialValues3);
/* ok so far, initialValues3 now contains the "English" entry */
initialValues3.put(KEY_LANG, "German");
initialValues3.put(KEY_ACT, "1");
/* initialValues3 now has both the "English" entry and the "German" one */
db.insert(LANGS_TABLE, null, initialValues3);
/* the "English" entry has now been added twice, and the "German" one once */
...etc
I think you might want to call initialValues3.clear()
after each insert.
As for the rest of the query, you are using a column KEY_SEN_ID_TH_SEN
that you have not provided us any details for.
精彩评论