zoukankan      html  css  js  c++  java
  • Android Studio 的初步使用,ContentProvider创建

    Android Studio 的教程文章链接

    http://www.open-open.com/lib/view/open1468121363300.html

    内容提供者可以把自己的数据库暴露给别人的应用程序访问。

    *创建一个类 Provider extends 继承 ContentProvider

    *在清单文件.xml里面配置 内容提供者。配置完整的路径和主机名。

    android:name="cn.itcast.contentprovider.PersonDBProvider"
    
    android:authorities="cn.itcast.contentprovider.personprovider"

    *在Provider类中定义出来一些数据操作的uri

    利用uriMarcher的方法添加一些指定的特殊路径

    matcher.addURI("cn.itcast.contentprovider.personprovider", "insert", 1);
    matcher.addURI("cn.itcast.contentprovider.personprovider", "delete", 2);
    matcher.addURI("cn.itcast.contentprovider.personprovider", "update", 3);
    matcher.addURI("cn.itcast.contentprovider.personprovider", "query", 4);

    *实现Provider增删该查的方法。

    ***

    使用内容提供者查询数据

    *获取内容提供者的解析器

    ContentResolver resolver=getContentResolver();

    *使用resolver进行增删该查的操作。

    Cursor cursor = contentResolver.query(uri, null, null, null, null);

    while(cursor.moveToNext()){
    int id = cursor.getInt(cursor.getColumnIndex("id"));
    String name = cursor.getString(cursor.getColumnIndex("name"));
    String number = cursor.getString(cursor.getColumnIndex("number"));
    Person p = new Person(id, name, number);
    persons.add(p);
    }
    cursor.close();

  • 相关阅读:
    跟结束进程相关的那些信号
    tcpdump使用示例
    Linux在bash history当中添加timestamp
    CentOS中在/etc/rc.local添加开机自启动项启动失败
    CentOS配置通过DHCP的方式动态获取IP
    CentOS桌面安装
    MySQL二进制安装
    对okhttp参数的一些思考
    依赖倒置原则(DIP)
    Liskov替换原则(LSP)
  • 原文地址:https://www.cnblogs.com/yboli/p/5663547.html
Copyright © 2011-2022 走看看