0

这是我的 onCreate 方法:

    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    if (intent.getData() == null)
        intent.setData(Formulas.CONTENT_URI);

    AutoCompleteTextView searchBar = (AutoCompleteTextView)findViewById(R.id.searchBar);
    Cursor c = getContentResolver().query(getIntent().getData(),new String[] { Formulas.TITLE }, null, null, null);
    SimpleCursorAdapter searchAdapter = 
        new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, c, 
                new String[] { Formulas.TITLE } , new int[] { android.R.id.text1} );
    searchBar.setAdapter(searchAdapter);
}

我确实在我的 databaseopenhelper 中输入了一些示例数据:

        @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE formula ( \n" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT, \n" +
                "title TEXT NOT NULL, \n" +
                "formula TEXT NOT NULL \n" +
                ");");
        db.execSQL("INSERT INTO formula VALUES ( \n" +
                "null, \"Pythagorean theorium\", \"a^2+b^2=c^2\" \n" +
                "); ");
        db.execSQL("INSERT INTO formula VALUES ( \n" +
                "null, \"Perimeter of a square\", \"l^2 * w^2\" \n" +
                "); ");
        db.execSQL("INSERT INTO formula VALUES ( \n" +
                "null, \"Area of a square\", \"l^4\" \n" +
                "); ");
    }

问题是我将适配器设置为AutoCompleteTextView,我希望使用该SQLiteDatabase.execSQL(String)方法插入的值。但是什么都没有?下拉框甚至不显示?我使用调试,发现Cursor不是空的,适配器也不是AutoCompleteTextView?可能是什么问题呢?我已经定义了自己的内容提供者。

4

1 回答 1

0

查询没有返回任何内容,因为内容 uri 有问题,完全是我的错。 是相关线程。

于 2010-08-22T20:40:57.987 回答