SimpleCursorAdapter is undefined?
Below is the sample of code giving me grief. The simpleCursorAdapter works if I put it outside of the textchangedlistener but not in I keep getting the message
The constructor SimpleCursorAdapter(new TextWatcher(){}, int, Cursor, String, int, null) is undefined
txt.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
//onTextChanged
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//beforeTextChanged
}
public void afterTextChanged(Editable s) {
//afterTextChanged
typedText = s.toString();
Cursor cur = db.rawQuery("SELECT * FROM " +
DB_TABLE +" where field LIKE '%" + typedText + "%'" , null);
String displayFields = "field";
int displayViews = R.id.bmark_visits;
setListAdapter(new SimpleCursorAdapter(this,
R.layout.testlist, cur,
displayFields, displayViews, null
)开发者_如何转开发);
}
});
The first parameter to the SimpleCursorAdapter
constructor should be your activity. However, inside of your anonymous TextWatcher
inner class, this
is the instance of the anonymous TextWatcher inner class. Use MyActivity.this
instead, where MyActivity
is the name of your activity.
You should call activity's manage cursor method. Otherwise, they will leak out.
activity.startManagingCursor( cursor );
Stéphane
精彩评论