So, I started using Realm, and everything works fine, and almost everything.
I use MultiAutoCompleteTextView to select some user (RealmObject)
so here:
this is my filter (inner class of my adapter)
private class UserFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint == null || constraint.length() == 0) {
filterResults.values = mUsers;
filterResults.count = mUsers.size();
} else {
final String lastToken = constraint.toString().toLowerCase();
final List<User> list = new ArrayList<>();
RealmQuery<User> query = realm.where(User.class);
query.contains("nickname", lastToken, false);
RealmResults<User> result = query.findAll();
list.addAll(result);
filterResults.values = list;
filterResults.count = list.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
mFilteredUsers = (List<User>) results.values;
if (results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
And in my adapter: in the getView method:
EGCUser user = getItem(position);
holder.mName.setText(user.getNickname());
the user is an invalid object, I tried so many different things and it didn’t work out. Therefore, I wonder what I can do with what I have achieved. I have a lot of problems with the stream, so maybe this is a problem with the inner class?
thank
EDIT: in this situation, where should I do Realm.getInstance ()?
Right now, I am passing the context in my adapter, and I am doing this in the adapter constructor, and I am storing the area object in a variable.
EDIT2: I got it to work, but I don’t know if this is how we should do it:
Filtering :
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
final List<User> list = new ArrayList<>();
Realm realm = Realm.getInstance(mContext);
RealmQuery<User> query = realm.where(User.class);
query.contains("nickname", lastToken, false);
RealmResults<User> result1 = query.findAll();
list.addAll(result1);
filterResults.values = list;
filterResults.count = list.size();
}
});
.