Coding the Note class
This is the fundamental data structure of the app. It is a class that we will write ourselves from scratch and has all the member variables we need to represent one user note. In Chapter 13, Handling and Displaying Arrays of Data, you will learn some new Java to understand how we can let the user have dozens, hundreds, or thousands of notes.
Create a new class by right-clicking on the folder with the name of your package, the one that contains the MainActivity.java
file. Select Java class under New and name it Note
. Click on OK to create the class.
Add the highlighted code to the new Note
class:
public class Note { private String mTitle; private String mDescription; private boolean mIdea; private boolean mTodo; private boolean mImportant; }
Note that our member variable names are prefixed with m
as per the Android convention. Furthermore, as there is no reason for any other class to access these variables directly, they are all declared private.
We...