【问题标题】:Android - Auto-complete from ListView with 2 textViewAndroid - 使用 2 个文本视图从 ListView 自动完成
【发布时间】:2015-05-19 02:15:02
【问题描述】:

在我的应用程序中有一个“搜索”区域,其中包含自动完成编辑文本和列表视图。 在 listView 的每个项目(在我的情况下为歌曲)我有 2 个 textView,但我的自动完成搜索行不起作用。

这是我的代码:

        lv = (ListView) findViewById(R.id.lvSearchList);
    inputSearch = (EditText) findViewById(R.id.etAutoComplete);

    // Adding items to listview
    adapter = new MySimpleArrayAdapter(
            this,
            songs
    );
    lv.setAdapter(adapter);

    /**
     * Enabling Search Filter
     * */
    inputSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            SearchSongs.this.adapter.getFilter().filter(cs);

        }

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

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
        }
    });

每次我输入序列文本时都没有任何变化。 谢谢

【问题讨论】:

  • Song 是一个包含字段的数组 - songName 和 songArtists(两个 textView)

标签: android listview autocomplete


【解决方案1】:

检查一下
http://developer.android.com/guide/topics/ui/controls/text.html#AutoComplete

搜索后你有一个新的适配器,你需要再次调用lv.setAdapter(adapter);来刷新你的列表视图,notifyDataSetChanged()可能会有所帮助

【讨论】:

  • 您发布的链接谈论的是简单的 textView,而不是 ListView。我认为问题是自动完成搜索不知道在哪里看(第一个 textview 或第二个),然后我不知道如何过滤列表
  • autoCompeteTextView 是一种 EditText 并提供建议。那么我们这里有什么?一个 EditText,它是用于搜索的文本和一个带有两个 textViews 的 listView?下一个问题是您要搜索什么?和 autoCompleteTextView 建议什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多