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); } }
查看全文
相关阅读:
新版《星光大道》
acl 3.1.2版本发布,网络通信与服务器编程框架
批量将 *.c 预处理为 *.i (递归处理文件夹中所有文件)gcc -E
texmaker——unknown graphics extension .eps
TexMaker
中国计算机学会推荐国际学术会议和期刊目录
浅谈阶梯博弈
【hdu 3389】Game
【hdu 3537】Daizhenyang's Coin
【hdu 3863】No Gambling
原文地址:https://www.cnblogs.com/badboy/p/2183712.html
最新文章
2018阿里云云数据库RDS核心能力演进
阿里毕玄:程序员的成长路线
MaxCompute表设计最佳实践
零距离接触阿里云时序时空数据库TSDB
轻松上云系列之二:其他云数据迁移至阿里云
离线批量数据通道Tunnel的最佳实践及常见问题
MaxCompute 表(Table)设计规范
阿里云开发者工具上手体验
轻松上云系列之一:本地数据迁移上云
Kubernetes重大漏洞?阿里云已第一时间全面修复
热门文章
五道口宅男
安装 Express —— CentOS 7
安装NodeJS & npm + npm常用命令
Port Node.js to Android running on Genymotion Emulator (x86)
ARM Translation on Genymotion
linux安装android NDK
Building and running Node.js for Android
Genymotion + ndk-build + adb
大学毕业生
Linux sed 高级用法实例
Copyright © 2011-2022 走看看