我在android中学习sqlite.对于sqlite,我正在使用developer.android.com.但是在阅读代码时我遇到了一些困惑.他们编写了FeedReaderContract构造函数以防止
实例化FeedReaderContract类但它们没有在任何地方定义FeedReaderContract类以及FeedReaderContract和FeedEntry之间的关系.
Here’s link我指的是.我提供代码.如何在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";
...
}
为了防止有人意外地实例化合同类,给它一个空的构造函数.
//Prevents the FeedReaderContract class from being instantiated.
private FeedReaderContract() {}
最佳答案
我理解为:
原文链接:https://www.f2er.com/android/430771.htmlpublic 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
}
因此,您无法实现合同,但可以访问所有内部类Constants.像示例行:
private static final String sql_CREATE_ENTRIES =
"CREATE TABLE " + FeedReaderContract.FeedEntry.TABLE_NAME + " (" +
FeedReaderContract.FeedEntry._ID + " INTEGER PRIMARY KEY," //continues
访问FeedReaderContract类中内部类的FeedEntry常量(TABLE_NAME和_ID).
希望能帮助到你.