FeedReaderContract的目的是什么,以及如何在OpenHelper类中定义内部类 [英] What is the purpose of FeedReaderContract and how to define inner class in OpenHelper Class
问题描述
我正在学习android中的SQLite.对于SQLite,我推荐使用developer.android.com.但是我在阅读代码时有些困惑.他们写了 FeedReaderContract
构造函数来防止实例化 FeedReaderContract
类,但是它们没有在任何地方定义 FeedReaderContract
类以及 FeedReaderContract
和 FeedEntry
之间的关系.
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
.
此处的链接.我提供代码.如何在openhelper类中定义内部类.有人可以建议我这个好方法吗?.
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() {}
推荐答案
我理解为:
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
}
因此,您不能使合同无效,但可以访问所有内部类的Constants.像示例行一样:
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
访问 FeedReaderContract
类中内部类的 FeedEntry
常量( TABLE_NAME
和 _ID
).
Access the FeedEntry
constants (TABLE_NAME
and _ID
) of the inner class in FeedReaderContract
class.
希望有帮助.
这篇关于FeedReaderContract的目的是什么,以及如何在OpenHelper类中定义内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!