【问题标题】:How to implement search bar using textWatcher in my application?如何在我的应用程序中使用 textWatcher 实现搜索栏?
【发布时间】:2018-01-02 20:33:33
【问题描述】:

在我的 android 项目 中,我的 editText 应该在键入时建议来自数据库的名称,其中包含每个字母。到目前为止,我搜索的是使用 TextChangedListener (TextWatcher)。 这似乎很简单,但我如何检查输入是否等于每个字母的光标中的数据?

这些是我的代码:

    b4.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2,
                                  int arg3) {
            // When user changed the Text
           Cursor a = db.getAllregisteredusers();


        }
        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1,
                                      int arg2, int arg3) {
            // TODO Auto-generated method stub

        }


    });

查询:

public Cursor getAllregisteredusers (){
    SQLiteDatabase db = DBHelper.getWritableDatabase();

    String selectQuery = "SELECT tableinfo.*, tableacc.*" +
            "FROM tableinfo JOIN tableacc ON tableinfo.userid = tableacc.userid WHERE tableacc.userstatus=? ";
    Cursor data = db.rawQuery(selectQuery , new String[]{ "REGISTERED"});


    return data;
}

我已经尝试过搜索,但我似乎无法得到它。我该怎么做?

【问题讨论】:

    标签: java android search textwatcher


    【解决方案1】:

    您应该为此使用Search Interface。最难的部分通常是创建一个数据库,听起来你已经有了一个。应该有很多关于创建搜索接口的github示例。

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多