我面临一个令人沮丧的问题,我有一个带有3个标签和3个ListView的活动,我正面临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):致命异常:主要 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):at 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):at java.lang.reflect.Method.invokeNative(Native Method) 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):at 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):at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
你开始另一个活动,这样就可以打开上一个要移除的活动,听起来就像是这样。要解决此问题,请将列表生成代码移至onResume,然后当您转到另一个活动并返回时,以及最初启动活动时,它将运行。