这是我的自定义适配器:
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
Cursor cursbbn = getCursor();
if (row == null)
{
LayoutInflater inflater = (LayoutInflater) localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.listtype, null);
}
String Title = cursbbn.getString(2);
String Readyin = cursbbn.getString(4);
String Faovoites=cursbbn.getString(8);
TextView titler=(TextView)row.findViewById(R.id.listmaintitle);
TextView readyinr=(TextView)row.findViewById(R.id.listreadyin);
int colorPos = position % colors.length;
row.setBackgroundColor(colors[colorPos]);
titler.setText(Title);
readyinr.setText(Readyin);
ImageView picture = (ImageView) row.findViewById(R.id.imageView1);
Bitmap bitImg = BitmapFactory.decodeResource(localContext.getResources(), R.drawable.seafood);
if(Title.contentEquals("Fajita Raps"))
picture.setImageBitmap(getRoundedCornerImage(bitImg));
if (Faovoites.contentEquals("YES")) {
ImageView star = (ImageView) row.findViewById(R.id.favoritesicon);
star.setVisibility(View.VISIBLE);
}
return row;
}
这是我的 Search Edittext aftertextchanged 事件
public void afterTextChanged(final Editable s) {
final String[] columns = new String[] {
"_id", COL_SanID, COL_SanTitle, COL_SanCat, COL_SanReadyin,
COL_SandServing, COL_SandIngred, COL_SandDirect, COL_SandFavor };
Bundle extrass = getIntent().getExtras();
final String Type = extrass.getString("CategoryType");
mAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
String value = "%" + constraint + "%";
String Type2 = "%" + Type + "%";
curs = mDb.query(TABLE_NAME, columns, COL_SanTitle
+ " LIKE ? And " + COL_SanCat + " LIKE ?",
new String[] { value, Type2 }, null, null,
COL_SanTitle + " ASC");
return curs;
}
});
最后: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(本机方法)