【问题标题】:Implementing recycler view using sugar ORM使用糖 ORM 实现回收器视图
【发布时间】:2018-05-14 23:15:55
【问题描述】:

我正在尝试将活动上的文本视图中的数据显示到片段上的回收器视图上。我有一个适配器类来实现适配器方法。但是,当我单击该片段时,应用程序将关闭,并且 .count 方法仍然无法解析。代码附在下面;

    public class NotesXFragment extends Fragment {




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View noteview = inflater.inflate(R.layout.fragment_notes, container, false);

        note_fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), AddNote.class));
            }
        });
        RecyclerView recyclerView = (RecyclerView) noteview.findViewById(R.id.note_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
       // notesDbAdapter = new NotesDbAdapter(getActivity(),notes);
     //   recyclerView.setAdapter(notesDbAdapter);

        notecount = Note.count(Note.class);
        if(notecount>=0){
            notes = Note.listAll(Note.class);
             notesDbAdapter = new NotesDbAdapter(getActivity(),notes);
             recyclerView.setAdapter(notesDbAdapter);
        }


        return noteview        }

}

【问题讨论】:

  • 您使用的是哪个版本的糖?如果您的应用程序崩溃,您应该发布您的堆栈跟踪
  • “和.count方法仍然无法解析”是什么意思?
  • 行notecount = Note.count(Note.class)
  • 由于某种原因 Note.class 显示为红色,当我点击它时,它只是说方法计数无法解析

标签: android orm sugarorm


【解决方案1】:

请检查您是否正确导入了 Note 类。此外,您可以尝试使用 SugarRecord 类来获取计数,我发现它比使用普通类更好。

notecount = SugarRecord.count(Note.class);

请检查您是否使用的是最新版本的库。 此外,每当您更新架构时,请在您的 AndroidManifest.xml 文件中增加您的数据库版本。

<meta-data android:name="VERSION" android:value="2" />

【讨论】:

  • Note 是否扩展了 Sugar Record?你能用打印的错误更新你的问题吗?
  • 我还不允许
  • 我已将错误附在问题的末尾,谢谢
  • 请问,你用的是哪个版本的糖?
  • 版本 2。我似乎不明白为什么我不能让 count 方法在类上工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多