こんにちは、StaleDataException というエラーが発生しています。このエラーは、リストのフィルター処理に使用している編集テキストが空白であるか、「いいね! 条件」に一致する場合に発生し続けます。カーソルを使用して新しい行を取得しようとしていますが、まだ答えが得られていないので、これに対する助けは素晴らしいでしょうか?
public class CBFilter extends ListActivity {
EditText Filter;
ListView RecipeNames;
Cursor cursor, c;
CBListAdapter adapter;
CBDataBaseHelper data, data2;
//SQLiteDatabase data2;
TextView RecipeText, RowId;
String[] from = { CBDataBaseHelper.KEY_NAME};
int[] to = { R.id.rowText};
ImageView image;
byte[] dataImage;
BufferedInputStream buf;
public static final String TAG = "Error";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//FileInputStream in;//= openFileInput("//STEFAN-PC/Users/stefan/Desktop/Uni Work/Image.jpg");
RecipeNames = (ListView) findViewById(android.R.id.list);
RecipeNames.setTextFilterEnabled(true);
RecipeText = (TextView) findViewById(R.id.recipeText);
Filter = (EditText) findViewById(R.id.search_box);
//adapter = new SimpleCursorAdapter (this, 0, cursor, null, null);
//image = (ImageView) findViewById(R.id.RecipeImage);
data = new CBDataBaseHelper(this);
data.open();
cursor = data.query();
startManagingCursor(cursor);
adapter = new CBListAdapter(this, 0, cursor, from, to);
RecipeNames.setAdapter(adapter);
adapter.notifyDataSetChanged();
Filter.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
try{
CBListAdapter filteradapter = (CBListAdapter)RecipeNames.getAdapter();
filteradapter.setFilterQueryProvider(filterQueryProvider);
//RecipeNames.setAdapter(filteradapter);
filteradapter.getFilter().filter(s);
filteradapter.notifyDataSetChanged();
}catch(Exception e){
Log.e(TAG, "sumthing wrong", e);
e.printStackTrace();
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void afterTextChanged(Editable s) {
}
});
}
public void CreateNew(View view){
Intent myIntent = new Intent(this, CBCreate.class);
startActivity(myIntent);
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
super.onListItemClick(parent, v, position, id);
Intent intent1 = new Intent(this, CBCreate.class);
long rowId = cursor.getLong(cursor.getColumnIndex(CBDataBaseHelper.KEY_ROWID));
String s = String.valueOf(rowId);
intent1.putExtra("SELECTED", s);
startActivity(intent1);
}
public FilterQueryProvider filterQueryProvider = new FilterQueryProvider() {
public Cursor runQuery(CharSequence _constraint) {
// CBDataBaseHelper dh2;
data.open();
Cursor c = data.filter(_constraint);
startManagingCursor(c);
Cursor cur = data.query();
if (TextUtils.isEmpty((_constraint ))){
if (cur != null && cur.moveToFirst()) {
return cur ;
}
cur.close();
}
return c;
}
};
// data2.open();
//return data2.filter(_constraint);
}