实例解析Android系统中的ContentProvider组件用法

2019-12-10 18:12:36于海丽

activity.xml

<LinearLayout xmlns:android="http://www.easck.com/apk/res/android" 
  xmlns:tools="http://www.easck.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  tools:context=".MainActivity" > 
 
  <ScrollView 
    android:id="@+id/scr1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 
 
      <Button 
        android:id="@+id/bt1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="添加" /> 
 
      <Button 
        android:id="@+id/bt2" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="删除" /> 
 
      <Button 
        android:id="@+id/bt3" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="更改" /> 
 
      <Button 
        android:id="@+id/bt4" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="查询" /> 
 
      <EditText 
        android:id="@+id/ed1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="输入name条件进行增删改查" /> 
 
      <EditText 
        android:id="@+id/ed2" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="输age条件进行增删改查" /> 
    </LinearLayout> 
  </ScrollView> 
 
  <ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
  </ListView> 
 
</LinearLayout> 

 
item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="horizontal" > 
  <TextView  
    android:id="@+id/item_txt1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    <TextView  
    android:id="@+id/item_txt2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
   
 
</LinearLayout>