【问题标题】:Android Listview Search filter (no result) [duplicate]Android Listview搜索过滤器(无结果)[重复]
【发布时间】:2015-09-13 18:16:41
【问题描述】:

我想在 android 中构建搜索过滤器但失败了...有什么解决方案吗?请帮帮我..这是我的代码:

BoxOfficeActivity.java

inputSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
if (adapterMovies==null) {
return;
}
BoxOfficeActivity.this.adapterMovies.getFilter().filter(cs);
Log.e(TAG, "OnTextChange: " + cs + " start: " + arg1 +
" before: " + arg2 + " count: " +arg3 + " adapter: " +
adapterMovies.getCount());
}


public void beforeTextChanged(CharSequence arg0, int arg1, 
int arg2, int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});

【问题讨论】:

  • BoxOfficeActivity.java 在哪里。它不可见
  • 还是不行,你能把代码贴出来而不是(试图发送)一个链接吗?
  • 我更新了我的代码...

标签: java android filter


【解决方案1】:

http://developer.android.com/guide/topics/search/search-dialog.html 的完整示例:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_label"
    android:hint="@string/search_hint" >
</searchable>

添加到清单:

<application ... >
    <!-- this is the searchable activity; it performs searches -->
    <activity android:name=".SearchableActivity" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
                   android:resource="@xml/searchable"/>
    </activity>

    <!-- this activity enables the search dialog to initiate searches
         in the SearchableActivity -->
    <activity android:name=".OtherActivity" ... >
        <!-- enable the search dialog to send searches to SearchableActivity -->
        <meta-data android:name="android.app.default_searchable"
                   android:value=".SearchableActivity" />
    </activity>
    ...
</application>

在 Java 中

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      doMySearch(query);
    }
}

【讨论】:

  • 如果我使用 TextWatcher?
  • 回答时该部分不可用...我会调查一下
猜你喜欢
  • 2011-12-22
  • 2013-02-10
  • 2018-09-24
  • 1970-01-01
  • 2012-01-14
  • 2020-08-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多