我正在尝试学习将RecyclerVIEw与Realm结合使用.我正在从here开始关注官方教程.
但是当我自己编写程序时,我在复制示例本身时遇到错误.
MyRecyclerVIEwAdapter官方示例代码发布在Realm的Github上here.
我的SubjectsAdapter代码是-
package in.medicalguru.adapters;import androID.support.v7.Widget.RecyclerVIEw;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.TextVIEw;import in.medicalguru.MainActivity;import in.medicalguru.R;import in.medicalguru.models.TimeStamp;import io.realm.OrderedRealmCollection;import io.realm.RealmRecyclerVIEwAdapter;public class SubjectsAdapter extends RealmRecyclerVIEwAdapter<TimeStamp, SubjectsAdapter.MyVIEwHolder> { private final MainActivity activity; public SubjectsAdapter(MainActivity activity, OrderedRealmCollection<TimeStamp> data) { super(data, true); this.activity = activity; } @OverrIDe public MyVIEwHolder onCreateVIEwHolder(VIEwGroup parent, int vIEwType) { VIEw itemVIEw = LayoutInflater.from(parent.getContext()) .inflate(R.layout.row, parent, false); return new MyVIEwHolder(itemVIEw); } @OverrIDe public voID onBindVIEwHolder(MyVIEwHolder holder, int position) { TimeStamp obj = getData().get(position); holder.data = obj; //holder.Title.setText(obj.getSubjectname()); holder.Title.setText(obj.getTimeStamp()); } class MyVIEwHolder extends RecyclerVIEw.VIEwHolder implements VIEw.OnLongClickListener { public TextVIEw Title; public TimeStamp data; public MyVIEwHolder(VIEw vIEw) { super(vIEw); Title = (TextVIEw) vIEw.findVIEwByID(R.ID.textvIEw); vIEw.setonLongClickListener(this); } @OverrIDe public boolean onLongClick(VIEw v) { //activity.deleteItem(data); return true; } }}
项目的build.grade的相关部分:
buildscript { repositorIEs { jcenter() } dependencIEs { classpath 'com.androID.tools.build:gradle:2.2.2' classpath "io.realm:realm-gradle-plugin:2.2.1" // NOTE: Do not place your application dependencIEs here; they belong // in the indivIDual module build.gradle files }}
模块的build.gradle的相关部分:
apply plugin: 'com.androID.application'apply plugin: 'realm-androID'dependencIEs { compile filetree(dir: 'libs', include: ['*.jar']) androIDTestCompile('com.androID.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.androID.support', module: 'support-annotations' }) compile 'com.androID.support:appcompat-v7:25.0.1' compile 'com.Google.androID.gms:play-services-ads:10.0.1' testCompile 'junit:junit:4.12' compile 'com.Google.code.gson:gson:2.4' compile 'org.glassfish:javax.annotation:10.0-b28' compile 'com.androID.support:recyclervIEw-v7:25.0.1' compile 'io.realm:androID-adapters:1.4.0'}
不幸的是,我对Realm并不陌生,我无法理解该错误的确切含义,所以我什至无法在Google上找到它.
解决方法:
IntelliJ提示说,构造函数的超级调用中的第一个参数应为Context.
尝试这个.
public SubjectsAdapter(MainActivity activity, OrderedRealmCollection<TimeStamp> data) { super(activity, data, true); this.activity = activity;}
总结 以上是内存溢出为你收集整理的如何在RecyclerView中使用Realm Android Adapter全部内容,希望文章能够帮你解决如何在RecyclerView中使用Realm Android Adapter所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)