Android数据库映射,使用dbcontract还是实体类?
2个回答
2016-02-02 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
Android数据库映射,使用dbcontract比较推荐:
举例如下:
package com.melissanoelle.groovebasin.data;
import android.content.ContentUris;
import android.net.Uri;
import android.provider.BaseColumns;
/**
* Created by mel on 2/21/15.
*/
public class DbContract {
public static final String CONTENT_AUTHORITY = "com.melissanoelle.groovebasin";
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
public static final String PATH_GROOVEBASIN = "groovebasin";
public static final class GroovebasinEntry implements BaseColumns {
public static final String TABLE_NAME = "groovebasins";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_URL = "url";
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_GROOVEBASIN).build();
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/" + CONTENT_AUTHORITY + "/" + PATH_GROOVEBASIN;
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/" + CONTENT_AUTHORITY + "/" + PATH_GROOVEBASIN;
public static Uri buildGroovebasinUri(long id) {
return ContentUris.withAppendedId(CONTENT_URI, id);
}
public static Uri returnContentUri() { return CONTENT_URI; }
}
}
举例如下:
package com.melissanoelle.groovebasin.data;
import android.content.ContentUris;
import android.net.Uri;
import android.provider.BaseColumns;
/**
* Created by mel on 2/21/15.
*/
public class DbContract {
public static final String CONTENT_AUTHORITY = "com.melissanoelle.groovebasin";
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
public static final String PATH_GROOVEBASIN = "groovebasin";
public static final class GroovebasinEntry implements BaseColumns {
public static final String TABLE_NAME = "groovebasins";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_URL = "url";
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_GROOVEBASIN).build();
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/" + CONTENT_AUTHORITY + "/" + PATH_GROOVEBASIN;
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/" + CONTENT_AUTHORITY + "/" + PATH_GROOVEBASIN;
public static Uri buildGroovebasinUri(long id) {
return ContentUris.withAppendedId(CONTENT_URI, id);
}
public static Uri returnContentUri() { return CONTENT_URI; }
}
}
浙江启扬智能科技有限公司
2023-06-12 广告
2023-06-12 广告
Android和ARM、Linux之间存在密切的联系。Android是一种基于Linux内核的嵌入式智能操作系统,它采用了ARM处理器作为其主要处理器架构。Android的内核和许多应用程序都是基于ARM架构编写的,包括处理器和内存管理器。...
点击进入详情页
本回答由浙江启扬智能科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询