【问题标题】:AutoCompleteTextView adapter not displaying dropdown?AutoCompleteTextView 适配器不显示下拉菜单?
【发布时间】:2010-08-22 01:47:05
【问题描述】:

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

【问题讨论】:

  • 为什么你的 sql 查询中有\ns 之类的东西?另外,有什么错误?发布堆栈跟踪或错误消息
  • @Falmarri 抱歉,我不清楚。我使用 ORM 创建数据库创建方法,然后将其粘贴到 eclipse 中并自动格式化。没有错误。当我为 AutoCompleteTextView 设置适配器时,我希望在下拉框中显示“正方形的面积”“勾股定理”和“正方形的周长”。但什么也没发生。

标签: java android sqlite android-contentprovider autocompletetextview


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    相关资源
    最近更新 更多