执行过滤器查询搜索时更改IllegalStateException方向

时间:2014-07-12 12:41:18

标签: android android-cursor android-searchmanager android-filter

我已使用自定义listview上的searchviewsetFilterQueryProviderSimpleCursorAdapter中实施了搜索。

在我的片段的onActivityCreated中,我通过以下代码设置过滤器

myAdapter.setFilterQueryProvider(new FilterQueryProvider(){

                @Override
                public Cursor runQuery(CharSequence constraint) {


                    returnget Activity().getBaseContext().getContentResolver().
                            query(  Uri.parse("content://com.DBProvider/getEmployeeByName"),
                            EMP.PROJECTION, EMP.EMP_NAME + " LIKE '"+ constraint+"%'", null, null);;

                }


            });

       // this code is outside `setFilterQueryProvider`
        getActivity().getSupportLoaderManager().initLoader(EMP_INFO.ID, null, this);

现在的问题是,当我改变方向时,我收到了IllegalStateException异常。

07-12 18:08:46.215: E/AndroidRuntime(3242): FATAL EXCEPTION: main
07-12 18:08:46.215: E/AndroidRuntime(3242): java.lang.IllegalStateException: attempt to re-open an already-closed object: net.sqlcipher.database.SQLiteQuery 
07-12 18:08:46.215: E/AndroidRuntime(3242):     at net.sqlcipher.database.SQLiteClosable.acquireReference(SQLiteClosable.java:34)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at net.sqlcipher.database.SQLiteQuery.fillWindow(SQLiteQuery.java:67)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at net.sqlcipher.database.SQLiteCursor.fillWindow(SQLiteCursor.java:290)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at net.sqlcipher.database.SQLiteCursor.onMove(SQLiteCursor.java:262)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:193)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:162)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:162)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:247)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.AbsListView.obtainView(AbsListView.java:2177)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1247)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.ListView.onMeasure(ListView.java:1159)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:302)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.View.measure(View.java:15848)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.Choreographer.doFrame(Choreographer.java:532)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.os.Handler.handleCallback(Handler.java:730)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.os.Looper.loop(Looper.java:137)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at android.app.ActivityThread.main(ActivityThread.java:5103)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at java.lang.reflect.Method.invokeNative(Native Method)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at java.lang.reflect.Method.invoke(Method.java:525)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-12 18:08:46.215: E/AndroidRuntime(3242):     at dalvik.system.NativeStart.main(Native Method)

修改

我发现以下行导致问题时,方向更改为内部onActivityCreated,所以我如何防止这种情况,在方向更改时我想要在最后一个搜索项目(之前的状态)。< / p>

    getActivity().getSupportLoaderManager().initLoader(EMP_INFO.ID, null, this);

1 个答案:

答案 0 :(得分:2)

尝试将此代码放在AndroidManifest中:

android:configChanges="keyboardHidden|orientation|screenSize"

希望不要迟到;)