2013-04-06 14 views
0

我正在搜索數據庫中的用戶輸入。這是一個字典應用程序。我有一個切換按鈕,允許用戶在兩​​種語言之間切換。它可以工作,但是當我切換到不同的語言時它不起作用。基本上我想申請一個不同的SQL查詢,當按鈕切換到另一種語言。使用不同的sql查詢切換按鈕

這裏是我的代碼:

try { 

     Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM fr_definition JOIN fr_adresse_definition ON fr_definition.data_id = fr_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null); 

     cursor.moveToFirst(); 
     if (cursor.getCount() != 0) { 

      if (word[1] == null || word[1].equals("English")) { 
       translatedWord = cursor.getString(2); 
      } else { 

       //dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM en_definition JOIN en_adresse_definition ON en_definition.data_id = en_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null); 
       translatedWord = cursor.getString(1); 
      } 
     } else { 
      translatedWord = "The word is not in database"; 
     } 
     cursor.close(); 
    } catch (SQLiteException sqle) { 
     translatedWord = "The word is not in database"; 
    } 

    dictionary.close(); 
+0

我不確定你在這裏問什麼。什麼不起作用?你是否想要被註釋掉的代碼能夠正常工作,但它不會?如果你不是英文的,你想使用不同的查詢嗎? – HalR 2013-04-06 14:19:30

+0

是的,當按下切換按鈕時,我想使用不同的查詢。 – user2047427 2013-04-06 14:22:02

回答

0

難道這樣的事情讓你使用你的其他查詢?

try { 
    Cursor cursor; 

    if (word[1] == null || word[1].equals("English")) { 
     cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM fr_definition JOIN fr_adresse_definition ON fr_definition.data_id = fr_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null); 
     cursor.moveToFirst(); 
     if (cursor.getCount() != 0) { 
      translatedWord = cursor.getString(2); 
     } 
    } else { 
     cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM en_definition JOIN en_adresse_definition ON en_definition.data_id = en_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null); 
     cursor.moveToFirst(); 
     if (cursor.getCount() != 0) { 
       translatedWord = cursor.getString(1); 
     } 
    } 

    cursor.close(); 
} catch (SQLiteException sqle) { 
    translatedWord = "The word is not in database"; 
} 

dictionary.close(); 
+0

是的,它的工作。非常感謝你。 – user2047427 2013-04-06 14:38:11

+0

不客氣。 – HalR 2013-04-06 14:47:46