2014-02-26 23 views
0

我需要你的幫助,請使用此代碼..在從SQLITE中選擇字符串時使用WHERE?

我要搜索的任何名稱,其中FIELD_CURRENCY =美元 結果將僅選擇貨幣等於美元的名稱。

private static final String FIELD_ID = "_id"; 
private static final String FIELD_NAME = "name"; 
private static final String FIELD_FLAG = "flag"; 
private static final String FIELD_TEL = "tel"; 
private static final String FIELD_CURRENCY = "currency"; 
private static final String TABLE_NAME = "countries"; 

    /** Returns Countries */ 
public Cursor getCountries(String[] selectionArgs) { 

    String selection = FIELD_NAME + " like ?"; 

    if (selectionArgs != null) { 
     selectionArgs[0] = "%" + selectionArgs[0] + "%"; 

我的表:

public class Country { 

    // Array of strings storing country names 
static String[] countries = new String[] { "India", "Pakistan", 
     "Sri Lanka", "China", "test", "Nepal", "Taza", 
     "Test", "test2", "Japan" }; 

// Array of integers points to images stored in /res/drawable 
static int[] flags = new int[] { R.drawable.india, R.drawable.pakistan, 
     R.drawable.japan, R.drawable.china, R.drawable.bangladesh, 
     R.drawable.japan, R.drawable.afghanistan, R.drawable.japan, 
     R.drawable.japan, R.drawable.japan }; 

// Array of strings to store currencies 
static String[] tel = new String[] { "0515155", 
      "054545454", "045154", "0154645", 
      "054685", "07700125", "0750", 
      "07540", "07540", "07540" }; 

// Array of strings to store currencies 
static String[] currency = new String[] { "Indian Rupee", 
     "Pakistani Rupee", "Sri Lankan Rupee", "Renminbi", 
     "dollar", "Nepalese Rupee", "Afghani", 
     "dollar", "South Korean Won", "dollar" }; 

}} 我 感謝您的幫助......

+0

'從貨幣'%doller%';'試試這個 –

回答

0

好了,把它添加到您的選擇:

String selection = FIELD_NAME + " like ? AND " + FIELD_CURRENCY + "='dollar'"; 
+0

謝謝laalto的幫助,但它表示令牌「FIELD_CURRENCY」上的語法錯誤,刪除此令牌 – user1710911

+0

錯過了一個'+運算符那裏,謝謝。 – laalto

+0

它也不起作用。 – user1710911

0

SELECT名字從國家WHERE貨幣='美元'