I am learning SQLite in android. For SQLite I am reffering developer.android.com. But I got some Confusion while reading the code. They wrote FeedReaderContract constructor to prevent
instantiating the FeedReaderContract class but they don't define FeedReaderContract class anywhere and the relation between FeedReaderContract and FeedEntry.
Here's link which I am referring to. I provide code. How can I define inner class in openhelper class. Could anybody suggest me the good way?.
For example, this snippet defines the table name and column names for a single table:
public static abstract class FeedEntry implements BaseColumns
{
public static final String TABLE_NAME = "entry";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_SUBTITLE = "subtitle";
...
}
To prevent someone from accidentally instantiating the contract class, give it an empty constructor.
//Prevents the FeedReaderContract class from being instantiated.
private FeedReaderContract() {}
I understand as:
public static class FeedReaderContract{
// Prevents the FeedReaderContract class from being instantiated.
private FeedReaderContract() {}
//The FeedEntry table definition
public static abstract class FeedEntry implements BaseColumns {
public static final String TABLE_NAME = "entry";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_SUBTITLE = "subtitle";
...
}
//more tables definition
}
So you can't instatiate the contract but can access all the inner classes Constants. Like the example line:
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + FeedReaderContract.FeedEntry.TABLE_NAME + " (" +
FeedReaderContract.FeedEntry._ID + " INTEGER PRIMARY KEY," //continues
Access the FeedEntry constants (TABLE_NAME and _ID) of the inner class in FeedReaderContract class.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With