我遇到了一个令人沮丧的问题,我有一个带有 3 个选项卡和 3 个 ListViews 的 Activity,我遇到了 OnItemClick 事件的问题。当我单击任何条目时,它会打开另一个活动并正确显示所需的结果,但是当我再次返回列表视图并尝试打开任何条目时,我得到了索引超出范围异常索引 -1 请求。没有意义的是,这 3 个中的一个列表视图可以正常工作,而其他 2 个则没有。下面是我的代码:
这个 OnResume () :
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(final Editable s) {
mAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
String value = "%" + constraint + "%";
String Type2 = "%" + jype + "%";
curs = mDb.query(TABLE_NAME, columns, COL_SanTitle
+ " LIKE ? And " + COL_SanCat + " LIKE ?",
new String[] { value, Type2 }, null, null,
COL_SanTitle + " ASC");
return curs;
}
});
fAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
String value = "%" + constraint + "%";
String Type2 = "%YES%";
cursF = mDb.query(TABLE_NAME, columns, COL_SandFavor
+ " LIKE ? And " + COL_SanTitle + " LIKE ?",
new String[] { Type2, value }, null, null,
COL_SanTitle + " ASC");
return cursF;
}
});
dAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
String value = "%" + constraint + "%";
String Type2 = "%" + jype + "%";
cursD = mDb.query(TABLE_NAME, columns, COL_SanTitle
+ " LIKE ? And " + COL_SanCat + " LIKE ?",
new String[] { value, Type2 }, null, null,
COL_SanTitle + " ASC");
cursD.moveToFirst();
return cursD;
}
}
);
fAdapter.getFilter().filter(s.toString());
mAdapter.getFilter().filter(s.toString());
dAdapter.getFilter().filter(s.toString());
mAdapter.notifyDataSetChanged();
fAdapter.notifyDataSetChanged();
dAdapter.notifyDataSetChanged();
mList.setAdapter(mAdapter);
fList.setAdapter(fAdapter);
dList.setAdapter(dAdapter);
cursD.moveToFirst();
cursS.moveToFirst();
curs.moveToFirst();
}
});
这是 Logcat 错误:
04-26 18:56:50.310: E/AndroidRuntime(878): 致命异常: main 04-26 18:56:50.310: E/AndroidRuntime(878): android.database.CursorIndexOutOfBoundsException: 请求索引-1,大小1 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.database.AbstractCursor.checkPosition(AbstractCursor.java:580) 04-26 18:56:50.310: E/AndroidRuntime(878): 在android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41) 04-26 18: 56:50.310: E/AndroidRuntime(878): 在 master.chef.mediamaster.Interface.onItemClick(Interface.java:781) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.widget.AdapterView .performItemClick(AdapterView.java:284) 04-26 18:56:50.310: E/AndroidRuntime(878):在 android.widget.ListView.performItemClick(ListView.java:3513) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.widget.AbsListView$PerformClick.run(AbsListView.java:1812) 04- 26 18:56:50.310: E/AndroidRuntime(878): 在 android.os.Handler.handleCallback(Handler.java:587) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.os。 Handler.dispatchMessage(Handler.java:92) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.os.Looper.loop(Looper.java:123) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 android.app.ActivityThread.main(ActivityThread.java:3683) 04-26 18:56:50.310: E/AndroidRuntime(878): 在 java.lang.reflect.Method.invokeNative(Native方法) 04-26 18:56:50.310: E/AndroidRuntime(878): at java.lang.reflect.Method.invoke(Method.java:507) 04-26 18:56:50.310: E/AndroidRuntime(878) : 在 com.android.internal.os。ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-26 18:56:50.310: E/AndroidRuntime(878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-26 18:56:50.310:E/AndroidRuntime(878):在 dalvik.system.NativeStart.main(本机方法)