类的拓展

随着Adroid的学习,有一些类经常出现,因此为了巩固对这些类的认识,我决定总结一下。

一、Uri
Uri的位置:android.net.Uri,是有Android对URI(位置为java.net.URI)的拓展,使其更加适应Android。
Uri的结构:因为学习的比较浅,所以Uri的结构就不深入分析了,结构:Content://+authority+path

二、UriMatch
UriMatch类主要用于匹配Uri
1.使用UriMatch类首先要初始化:
UriMatch urimatch=new UriMatch(UriMatch.NO_MATCH);
2.注册相应的Uri
urimatch.addURI();
3.与已经注册的Uri进行匹配。
Uri uri=Uri.parse(“Content://+authority+path”);
int match=urimatch.match(uri);
//uri跟UriMatch我在编写内容提供器的时候用得比较多,其余的地方还没用到。(因为我还比较菜 TAT)

三、SQLiteDatbase
位置:android.database.sqlite.SQLiteDatabase
下面我列举几个我使用SQLiteDatabase最常用的几个方法(删查增改)。
1.int delete(String table, String whereClause, String[] whereArgs) Convenience method for deleting rows in the database.
2.long insert(String table, String nullColumnHack, ContentValues values) Convenience method for inserting a row into the database.
3.Cursor query(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given URL, returning a Cursor over the result set.

Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given table, returning a Cursor over the result set.

Cursor query(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal)
Query the given URL, returning a Cursor over the result set.

Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
Query the given table, returning a Cursor over the result set
query方法接收的参数有很多种,一般只用7个参数的那个query方法,返回类型都是Cursor。
4.int update(String table, ContentValues values, String whereClause, String[] whereArgs) Convenience method for updating rows in the database.

四、Cursor
Cursor 是每行的集合。
1.使用 moveToFirst() 定位第一行。你必须知道每一列的名称。你必须知道每一列的数据类型。Cursor 是一个随机的数据源。所有的数据都是通过下标取得
2.关于Cursor比较重要的方法:
lose()
关闭游标,释放资源
copyStringToBuffer(int columnIndex, CharArrayBuffer buffer)
在缓冲区中检索请求的列的文本,将将其存储
getColumnCount()
返回所有列的总数
getColumnIndex(String columnName)
返回指定列的名称,如果不存在返回-1
getColumnIndexOrThrow(String columnName)
从零开始返回指定列名称,如果不存在将抛出IllegalArgumentException 异常。
getColumnName(int columnIndex)
从给定的索引返回列名
getColumnNames()
返回一个字符串数组的列名
getCount()
返回Cursor 中的行数
moveToFirst()
移动光标到第一行
moveToLast()
移动光标到最后一行
moveToNext()
移动光标到下一行
moveToPosition(int position)
移动光标到一个绝对的位置
moveToPrevious()
移动光标到上一行