我想根据从sqlite数据库中选择的时间(选择)将数据加载到不同的listView(相同的活动),但是我不知道为什么我的应用程序不断崩溃... 请有人告诉我下面的代码有什么问题...
在MainActivity.java
mCursorAdapter = new FoodCursorAdapter(this,null);
mCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return FP.fetchdatabyfilter(constraint.toString(),"time" );
}
});
mCursorAdapter.getFilterQueryProvider().runQuery("D");
dinner.setAdapter(mCursorAdapter);
在FoodProvider.java
public Cursor fetchdatabyfilter(String inputText, String filtercolumn) throws SQLException {
String selection = filtercolumn + "=?";
String[] selectionArgs = {inputText};
String[] projection = {
FoodEntry._ID,
FoodEntry.COLUMN_FOOD_NAME,
FoodEntry.COLUMN_FOOD_CALORIES,
FoodEntry.COLUMN_FOOD_TIME
};
Cursor row = null;
if (inputText == null || inputText.length() == 0 ) {
row = getContext().getContentResolver().query(FoodEntry.CONTENT_URI, projection,null,null,null);
} else {
row = getContext().getContentResolver().query(FoodEntry.CONTENT_URI, projection,selection,selectionArgs,null);
}
if (row != null)
{
row.moveToFirst();
}
return row;
}