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); } }
查看全文
相关阅读:
U盘引导Linux安装 CentOS .3
Linux CentOS 6.3 网络连接 修复 虚拟机共享主机网络
内存中“堆”和“栈”的区别
求助帖--C++中单引号' '内多个字符是什么意思
Cent Os6.3 设置中文输入法
WPF中调用matlab制作的dll进行图像处理
Python中的round()函数原理
Eclipse+Pydev环境搭建
5-4-shell:数组
5-3-shell:流程控制--判断循环
原文地址:https://www.cnblogs.com/badboy/p/2183712.html
最新文章
接口幂等性
ajax 跨域请求
百度地图poi搜索框
java后台ssm框架集成极光推送详细步骤及处理思路
MySQL Explain详解
在linux环境中,让springboot 打包的jar服务运行在后台进程
kindeditor富文本编辑器的使用
nuzt 上传zip文件并
spring 设置外部图片文件访问路由
guava cache(LoadingCache)使用和源码分析
热门文章
JS——JSON学习
4.22——Js学习get到知识点
CSS速成教程—CSS盒子模型——6
CSS速成教程—样式2——5
CSS速成教程—CSS样式文本——4
CSS速成教程—介绍网页背景——3
CSS速成教程——2
CSS速成教程——1
HTML起步——学习4
scala安装介绍
Copyright © 2011-2022 走看看