我在android中学习SQLite.对于SQLite,我正在使用developer.android.com.但是在阅读代码时我遇到了一些困惑.他们写道FeedReaderContract构造,以防止实例化FeedReaderContract类,但他们没有定义FeedReaderContract任何地方和类之间的关系FeedReaderContract和FeedEntry.
这是我所指的链接.我提供代码.如何在openhelper类中定义内部类.有人能建议我这么好吗?
例如,此代码段定义单个表的表名和列名:
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";
...
}
Run Code Online (Sandbox Code Playgroud)
为了防止有人意外地实例化合同类,给它一个空的构造函数.
//Prevents the FeedReaderContract class from being instantiated.
private FeedReaderContract() {}
Run Code Online (Sandbox Code Playgroud)
我理解为:
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
}
Run Code Online (Sandbox Code Playgroud)
所以你不能实例化合约,但可以访问所有内部类常量。就像示例行一样:
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + FeedReaderContract.FeedEntry.TABLE_NAME + " (" +
FeedReaderContract.FeedEntry._ID + " INTEGER PRIMARY KEY," //continues
Run Code Online (Sandbox Code Playgroud)
在类中访问内部类的FeedEntry常量(TABLE_NAME和) 。_IDFeedReaderContract
希望能帮助到你。
| 归档时间: |
|
| 查看次数: |
2229 次 |
| 最近记录: |