zoukankan
html css js c++ java
ContentProvider简单使用
package com.song; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract.Contacts; import android.widget.ListView; import android.widget.SimpleCursorAdapter; public class ContactsListActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ListView listView = new ListView(this); // 得到联系人目录 Cursor cursor = getContentResolver().query(Contacts.CONTENT_URI, null, null, null, null); //在使用数据库的时候,使用完需要关闭。使用cursor的时候,可以将cursor的生命周期交给activity托管 startManagingCursor(cursor); /*在item中只显示属性的时候,可以直接使用android.R.layout.simple_expandable_list_item_1, * 这个系统默认的item布局,只包含一个textview. * String[] from = new String[] { Contacts._ID, Contacts.DISPLAY_NAME }; * int[] to = new int[] { android.R.id.text2, android.R.id.text1 }; * SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, * android.R.layout.simple_expandable_list_item_1, cursor, from, to); */ //需要显示多个的时候,可以自己写一个listview_item.xml String[] from = new String[] { Contacts._ID, Contacts.DISPLAY_NAME }; int[] to = new int[] { R.id.tv_id, R.id.tv_name }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview_item, cursor, from, to); listView.setAdapter(adapter); setContentView(listView); } }
查看全文
相关阅读:
win10下VMware15运行ubuntu18.04无法和主机之间复制粘贴问题
Redis的五种数据类型
celery的入门使用
Django/Flask的一些实现方法
Python3实现简单的钉钉机器人调用
装饰者模式
pyhdfs安装
使用setup.py安装python包和卸载python包的方法
zookeeper搭建
S3C6410裸奔之旅——RVDS2.2编译、仿真、调试过程 LED流水灯---转的
原文地址:https://www.cnblogs.com/badboy/p/2183712.html
最新文章
模块的导入
装饰器--装饰器的种类
高级装饰器---验证用户登录
装饰器--万能传参
装饰器--初识
随机验证码
函数--内置函数
函数--要点
函数--动态参数
函数--静态参数
热门文章
hive on spark
Spark SQL解析Json
ssh免密登录
Linux常用命令
hadoop环境搭建
vim命令备忘录
subline text居然没有自动保存......
eclipse修改java web项目在浏览器上的路径
Android studio变量重命名引发崩溃
哪个还没五杀?---文件查找
Copyright © 2011-2022 走看看