ui更新数据库 记录
来源:互联网 发布:力港网络客服电话 编辑:程序博客网 时间:2024/05/15 08:32
import android.content.ContentProvider;import android.content.ContentValues;import android.content.UriMatcher;import android.database.Cursor;import android.net.Uri;public class MyContentProvider extends ContentProvider { private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH); private static final int CALL=1; private static final int APP=2; private static final int SMS=3; private static final int MUSIC=4; private static final int SNS=5; private static final int WORD=6; private static final int BROWSER=7; private static final int TIME=8; static{ MATCHER.addURI("provider.MyContentProvider", "call", CALL); MATCHER.addURI("provider.MyContentProvider","app", APP); MATCHER.addURI("provider.MyContentProvider", "sms", SMS); MATCHER.addURI("provider.MyContentProvider", "music", MUSIC); MATCHER.addURI("provider.MyContentProvider", "sns", SNS); MATCHER.addURI("provider.MyContentProvider", "word", WORD); MATCHER.addURI("provider.MyContentProvider", "browser",BROWSER); MATCHER.addURI("provider.MyContentProvider", "time",TIME); } private DBHandler dbHandler=null;@Overridepublic int delete(Uri uri, String selection, String[] selectionArgs) {// TODO Auto-generated method stubreturn 0;}@Overridepublic String getType(Uri uri) {// TODO Auto-generated method stubreturn null;}@Overridepublic Uri insert(Uri uri, ContentValues values) {// TODO Auto-generated method stubswitch (MATCHER.match(uri)) {case CALL: dbHandler.insert("call", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;case APP: dbHandler.insert("appstate", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;case SMS:dbHandler.insert("sms", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;case MUSIC:dbHandler.insert("music", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;case SNS:dbHandler.insert("sns", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;case WORD:dbHandler.insert("search", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;case BROWSER:dbHandler.insert("browser", values);getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(TIME_URI, null);return uri;default:break;}return null;}@Overridepublic boolean onCreate() {LauncherActivity.context = getContext();if(dbHandler==null)dbHandler=DBHandler.getInstance();return true;}@Overridepublic Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {// TODO Auto-generated method stubCursor cursor=null;switch (MATCHER.match(uri)) {case CALL:cursor = dbHandler.rawQuery("select _id,people,number,duration,is_incoming, datetime(date,'unixepoch','localtime') from call order by date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case APP: cursor = dbHandler.rawQuery("select _id,package_name,state,datetime(date,'unixepoch','localtime') from appstate order by date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case SMS:cursor = dbHandler.rawQuery("select sms._id, sms.number,textcontent.content,sms.is_inbox, datetime(sms.date,'unixepoch','localtime') from sms inner join textcontent on sms.textcontent_id=textcontent._id order by sms.date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case MUSIC:cursor = dbHandler.rawQuery("select _id,title,artist,album,genre,composer,name,duration,datetime(date,'unixepoch','localtime') date,filepath from music order by date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case SNS:cursor = dbHandler.rawQuery("select sns._id, textcontent.content,sns.type,datetime(sns.date,'unixepoch','localtime'),sns.sid from sns inner join textcontent on sns.textcontent_id=textcontent._id order by sns.date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case WORD:cursor = dbHandler.rawQuery("select _id, words,datetime(date,'unixepoch','localtime') from search order by date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case BROWSER:cursor = dbHandler.rawQuery("select _id,url,title,visits, datetime(date,'unixepoch','localtime') from browser order by date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;case TIME:cursor = dbHandler.rawQuery("select * from ( select _id, title t1,url t2, datetime(date,'unixepoch','localtime') date, 'browser' type,'bro' path from browser union all select _id, people t1, number t2,datetime(date,'unixepoch','localtime') date, 'call' type,'bro' path from call union all select _id,title t1, artist t2,datetime(date,'unixepoch','localtime') date,'music' type,filepath path from music union all select sns._id,sns.type t1,textcontent.content t2, datetime(sns.date,'unixepoch','localtime') date,'SNS' type,'bro' path from sns left join textcontent on textcontent._id=sns.textcontent_id union all select sms._id,number t1,textcontent.content t2, datetime(sms.date,'unixepoch','localtime') date,'SMS' type,'bro' path from sms left join textcontent on textcontent._id=sms.textcontent_id union all select _id, '' t1, words t2, datetime(date,'unixepoch','localtime') date,'search' type,'bro' path from search union all select _id,package_name t1,state t2,datetime(date,'unixepoch','localtime') date,'app' type,'bro' path from appstate) order by date desc");cursor.setNotificationUri(getContext().getContentResolver(), uri);return cursor;default:break;}return null;}@Overridepublic int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {// TODO Auto-generated method stubreturn 0;}}
下个是 cursorloader
import android.content.Context;import android.content.CursorLoader;import android.database.Cursor;import android.net.Uri;public class MyCursorLoader extends CursorLoader { Cursor mCursor;public MyCursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {super(context, uri, projection, selection, selectionArgs, sortOrder);} @Override public void onContentChanged() { if (!mCursor.isClosed()) { deliverResult(mCursor); } forceLoad(); } @Override public Cursor loadInBackground() { mCursor = super.loadInBackground(); return mCursor; }}
- ui更新数据库 记录
- PHP更新数据库记录
- ContentProvider之数据库更新UI
- 记录跨线程更新UI 问题
- php 写数据库更新记录
- AndroidのContentProvider之数据库更新UI
- android实现数据库和UI同步更新
- Android 通过ContentProvider数据库更新UI
- Android 通过ContentProvider数据库更新UI
- GCD在子线程中更新UI出错记录
- Android 开发记录之UI篇(持续更新)
- LISP 简单的数据库 3.7 更新记录
- 更新ui
- 更新ui
- 更新UI
- mysql数据库中关于记录存在,更新记录,记录不存在,插入记录的sql语句编写
- Easy UI + Servlet + MySQL 显示数据库里面的记录
- 连接数据库'2.添加记录'3 更新数据(Access)
- Linux cpufreq 机制详细解析
- 远程注入DLL(简单描述)
- gevent学习2- 并行ping
- Unicode与UCS的历史恩怨
- log device is empty!
- ui更新数据库 记录
- Java中对象的复制
- 递归与分治策略
- Smart Client Software Factory "Add View (with presenter)" 等菜单不出来
- cgroup--blkio子系统测试-2(配合fio 做weight测试)
- cygwin下git图形界面gitk和git gui安装
- 【容器转换成为指定数组】
- GB2312,GBK与中文网页
- 百层楼扔棋子问题