2013-08-05 53 views
0

跟着這個tutorial,在SimpleCursorAdapter中遇到了光標問題。在教程示例中按預期工作。在我的代碼中顯示錯誤「構造函數SimpleCursorAdapter未定義」。不知道什麼是未定義的。代碼如下所示:SimpleCursorAdapter中的光標問題

Cursor cursor = null; 
    if (inputText == null || inputText.length() == 0) { 
     cursor = myDataBase.query(true, GL_TABLE, new String[] { GL_ID, 
       GL_FK, GL_LANG, GL_VALUE}, GL_FK 
       + " like '%" + inputText + "%'", null, null, null, null, 
       null); 

    } else { 
     cursor = myDataBase.query(true, GL_TABLE, new String[] { GL_ID, 
       GL_FK, GL_LANG, GL_VALUE}, GL_VALUE 
       + " like '%" + inputText + "%'", null, null, null, null, 
       null); 
    } 
    if (cursor != null) { 
     cursor.moveToFirst(); 
    } 

    String[] columns = new String[] { GL_FK, GL_LANG, GL_VALUE}; 

    int[] to = new int[] { R.id.tvWord, R.id.tvMeaning, R.id.tvKanji}; 

    dataAdapter = new SimpleCursorAdapter(this, R.layout.listword, 
      cursor, columns, to, 0); 
+0

錯誤在這裏:dataAdapter = new SimpleCursorAdapter(this,R.layout.listword, ** cursor **,columns,to ,0); –

回答

1

您是否導入了類?

import android.widget.SimpleCursorAdapter; 

如果確實如此,請務必使用正確的參數調用構造函數。 「這個」應該代表一種活動或背景。如果您處於Runnable或Clicklistener中,您必須調用超級MyActivty.this

+0

感謝一羣我的朋友:)你給了我主要提示:改變this-> mContext(我不知道這是什麼,但它工作)。謝謝你! –