I am using the Realm recyclerview.
compile ('com.github.thorbenprimke:realm-recyclerview:0.9.4') {
exclude module: 'realm-android'
}
Together with the normal Realm v2.0.2 ( latest )
The problem is when I run my code now I get
java.lang.NoSuchMethodError: No virtual method getTable()Lio/realm/internal/TableOrView; in class Lio/realm/RealmResults; or its super classes (declaration of 'io.realm.RealmResults' appears in /data/data/pandapixl.nl.studiebarometer/files/instant-run/dex/slice-io.realm-realm-android-library-2.0.2_65286432d702dab629d2322a66a4c74d2cf9a7e2-classes.dex) at io.realm.RealmBasedRecyclerViewAdapter.(RealmBasedRecyclerViewAdapter.java:162) at io.realm.RealmBasedRecyclerViewAdapter.(RealmBasedRecyclerViewAdapter.java:129) at io.realm.RealmBasedRecyclerViewAdapter.(RealmBasedRecyclerViewAdapter.java:119)
I think its because I am using a realm version that is way higher than the recyclerview supports. Is there a way to run 2 different versions of Realm without getting an error of duplicates in the APK? or is there a way to create a recyclerview myself without using the one I am using now? It doesn't need to be fancy. A basic one will do.
答案 0 :(得分:1)
That's what the realm/realm-android-adapters
project is for.
compile 'io.realm:android-adapters:1.3.0'
With RealmRecyclerViewAdapter
.
EDIT:
adapter = new RealmRecyclerViewAdapter<Dog, DogViewHolder>(getContext(), realm.where(Dog.class).findAllAsync(), true) {
@Override
public DogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new DogViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_dog_item, parent, false));
}
@Override
public void onBindViewHolder(DogViewHolder holder, int position) {
Dog dog = getData().get(position);
holder.bind(dog);
}
};
recyclerView.setAdapter(adapter);
Or
public class DogAdapter extends RealmRecyclerViewAdapter<Dog, DogViewHolder> {
public DogAdapter(Context context, RealmResults<Dog> results) {
super(context, results, true);
}
@Override
public DogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new DogViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_dog_item, parent, false));
}
@Override
public void onBindViewHolder(DogViewHolder holder, int position) {
Dog dog = getData().get(position);
holder.bind(dog);
}
};