java.lang.IllegalStateException: You cannot call onTextChanged with a non filterable adapter
来源:互联网 发布:郑州大学网络教育学费 编辑:程序博客网 时间:2024/06/05 00:23
原因:项目里要做一个通讯录搜索功能,ListView的headview里有一个editText,通过给editText.addTextChangedListener(TextWatcher tw)来给外界提供接口,但是在搜索的过程中一直报错:
08-04 07:44:31.883: E/AndroidRuntime(1800): FATAL EXCEPTION: main08-04 07:44:31.883: E/AndroidRuntime(1800): java.lang.IllegalStateException: You cannot call onTextChanged with a non filterable adapter08-04 07:44:31.883: E/AndroidRuntime(1800): at android.widget.AbsListView.onTextChanged(AbsListView.java:5757)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.widget.TextView.sendOnTextChanged(TextView.java:7372)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.widget.TextView.handleTextChanged(TextView.java:7431)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:9142)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:966)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:500)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:435)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:30)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:677)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:201)08-04 07:44:31.883: E/AndroidRuntime(1800): at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:183)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:85)08-04 07:44:31.883: E/AndroidRuntime(1800): at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:288)08-04 07:44:31.883: E/AndroidRuntime(1800): at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:83)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.os.Handler.dispatchMessage(Handler.java:99)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.os.Looper.loop(Looper.java:137)08-04 07:44:31.883: E/AndroidRuntime(1800): at android.app.ActivityThread.main(ActivityThread.java:5457)08-04 07:44:31.883: E/AndroidRuntime(1800): at java.lang.reflect.Method.invokeNative(Native Method)08-04 07:44:31.883: E/AndroidRuntime(1800): at java.lang.reflect.Method.invoke(Method.java:525)08-04 07:44:31.883: E/AndroidRuntime(1800): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)08-04 07:44:31.883: E/AndroidRuntime(1800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)08-04 07:44:31.883: E/AndroidRuntime(1800): at dalvik.system.NativeStart.main(Native Method)
从日志来看是与adapter以及filterable有关,搜索了大半天也没有什么有用的资料,只是知道了filterable是个接口,通常由adapter实现,用来过滤筛选数据。
实现它必须实现的方法: public Filter getFilter();
另外它还有两个比较重要的方法:
protected FilterResults performFiltering(CharSequence prefix); 从方法名可以猜出 这里执行过滤;
protected void publishResults(CharSequence constraint,FilterResults results);发布结果,通常用来刷新adapter
我尝试着把自己的adapter实现filterable接口,然后自己写了一个Filter,问题就解决了。。。。有些莫名其妙!!!
1.首先实现接口
@Override public Filter getFilter() { // TODO Auto-generated method stub if (null==mFilter) { mFilter = new MyFilter(); } return mFilter; }2.写一个Filter
private MyFilter mFilter; private class MyFilter extends Filter{ @Override protected FilterResults performFiltering(CharSequence constraint) { return null; } @Override protected void publishResults(CharSequence constraint,FilterResults results) { } }
就这样,不会再报java.lang.IllegalStateException: You cannot call onTextChanged with a non filterable adapter了。
0 0
- java.lang.IllegalStateException: You cannot call onTextChanged with a non filterable adapter
- java.lang.IllegalStateException The specified child already has a parent. You must call removeView()
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView
- java.lang.IllegalStateException The specified child already has a parent. You must call removeView()
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- Android—java.lang.IllegalStateException: The specified child already has a parent. You must call rem
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView
- android异常:java.lang.IllegalStateException: The specified child already has a parent. You must call r
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView(
- 知识点:文件读写 (字符流和字符流),属性文件的读取与文件的切割合并
- POJ - 1006 Biorhythms (中国剩余定理)
- error C2061: 语法错误: 标识符“__RPC__out_xcount_part” VS2010
- HDU 2639 Bone Collector II 背包k优解
- linux学习笔记4----vim编辑器
- java.lang.IllegalStateException: You cannot call onTextChanged with a non filterable adapter
- 3.3-多个栈组合模拟一个栈
- struts1源码学习6(doPost和doGet)
- 如何调用DLL
- Jquery json jsp实例
- Leetcode--Divide Two Integers
- 基于gnu-arm-linux的LPC2220的简单工程模板
- HDU 4902 Nice boat(线段树 区间更新)
- ural 1932 The Secret of Identifier (容斥原理)