使用糖ORM实施回收者视图

时间:2018-02-13 01:06:29

标签: android orm sugarorm

我正在尝试将活动上的textview数据显示在片段的回收器视图上。我有一个适配器类来实现适配器方法。但是当我点击片段时,应用程序关闭,而.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        }

}

1 个答案:

答案 0 :(得分:1)

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

notecount = SugarRecord.count(Note.class);

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

<meta-data android:name="VERSION" android:value="2" />
相关问题