AutoCompleteTextView适配器不显示下拉列表?

时间:2010-08-22 01:47:06

标签: java android sqlite android-contentprovider autocompletetextview

这是我的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不是null,也不是适配器或AutoCompleteTextView?可能是什么问题呢?我已经定义了自己的contentprovider。

1 个答案:

答案 0 :(得分:0)

查询没有返回任何内容,因为内容uri错误而且完全是我的错。 Here是相关主题。