Android-ContentResolver内容访问者
来源:互联网 发布:梭哈网络用语什么意思 编辑:程序博客网 时间:2024/05/17 23:18
ContentResolver 介绍说明
ContentResolver是通过URI来查询ContentProvider中提供的数据。除了URI以外,还必须知道需要获取的数据段的名称,以及此数据段的数据类型。
那么小编通过ContentResolver接收上一篇的ContentProvider的一个简单的列子。
查询所有
查询单个
activity_main.xml
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入ID" android:id="@+id/et_main_id" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="查询" android:onClick="query" /> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/lv_main_list" ></ListView>
item_listview.xml
<TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/iv_item_listview_id" /> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/iv_item_listview_name" /> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/iv_item_listview_age" />
MainActivity.java
public class MainActivity extends AppCompatActivity { private ContentResolver contentResolver; private ListView lv_main_list; private Cursor cursor; private SimpleCursorAdapter adapter; private EditText et_main_id; private Uri uri; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //得到内容访问者 contentResolver = getContentResolver(); lv_main_list = (ListView) findViewById(R.id.lv_main_list); et_main_id = (EditText) findViewById(R.id.et_main_id); //适配器 adapter = new SimpleCursorAdapter(this, R.layout.item_listview,cursor,new String[]{"_id","pname","page"},new int[]{R.id.iv_item_listview_id,R.id.iv_item_listview_name,R.id.iv_item_listview_age}); lv_main_list.setAdapter(adapter); } public void query(View view){ if(TextUtils.isEmpty(et_main_id.getText())){ //查询所有// et_main_id.setError("不能为空"); uri = Uri.parse("content://com.example.sj_provider.data/persons"); }else{ String id=et_main_id.getText().toString(); //查询单个 uri = Uri.parse("content://com.example.sj_provider.data/persons/"+id); } //查询 cursor = contentResolver.query(uri,null,null,null,null); //通知适配器发生改变 adapter.changeCursor(cursor); //adapter.notifyDataSetChanged(); }}
0 0
- android-内容访问者contentResolver
- Android-ContentResolver内容访问者
- android之ContentResolver内容访问者
- Android----ContentProvider(内容提供者) ContentResolver(内容访问者)
- ContentResolver(内容访问者)
- Android 中ContentProvider内容提供者和ContentResolver内容访问者
- Android ContentProvinder(内容提供者) ContentResolver(内容访问者)的简单应用
- Android:内容提供者(ContentProvider)和内容访问者(ContentResolver)
- Android ContentProvider(内容提供者 )+ContentResolver(内容访问者)
- Android之ContentProvider(内容的提供者)与ContentResolver(内容访问者)
- ContentResolver(内容访问者)访问通讯录
- ContentProvider内容提供者与ContentResolver内容访问者
- ContentProvider内容提供者 和 ContentResolver内容访问者
- ContentProvider内容提供者和ContentResolver内容访问者
- ContentProvider内容提供者与ContentResolver内容访问者
- ContentProvider内容提供者和ContentResolver内容访问者
- ContentProvider内容提供者与ContentResolver内容访问者
- ContentProvider内容提供者和ContentResolver内容访问者
- 如何提高生产力(四)、兼职为什么很难操作-
- Android HorizontalScrollView左右滑动
- Crashlytics-Android崩溃(crash)统计工具使用教程
- jbpm工作流学习手册
- Python获取邮箱内容并解析
- Android-ContentResolver内容访问者
- Linux信号处理机制
- 油田信息化:通往智慧之路(1.3-智慧油田在全球的实践)
- BZOJ 2152: 聪聪可可【树形dp
- GreenDao系列之(2)设计及机制介绍
- dubbo简介
- 客户端检测之能力检测
- LeetCode 39. Combination Sum
- Python爬虫:BeautifulSoup的find()和findAll()