ContentProvider对外共享数据的时候的query()方法是需要一个cursor的,
但是如果没有数据库,而项目又需要从ContentProvider读取数据的时候怎么办?
更糟糕的是其他方法操作也都是需要cursor的。
此时就需要MatrixCursor了,它相当于为你模拟了一个表。
废话不多说直接贴代码:

public class List1 extends ListActivity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);       // setContentView(R.layout.main);        String[] menuCols = new String[] {"_id", "item", "price" };        int[] to = new int[] { R.id.icon, R.id.item, R.id.price };        MatrixCursor menuCursor = new MatrixCursor(menuCols);        startManagingCursor(menuCursor);        menuCursor.addRow(new Object[] { R.drawable.icon, "Chicken Sandwich", "$3.99" });        ListAdapter menuItems = new SimpleCursorAdapter( this, R.layout.menu_row, menuCursor, menuCols, to);        setListAdapter(menuItems);    }}<?xml version="1.0" encoding="utf-8"?><LinearLayout    android:layout_width="fill_parent"        android:layout_height="fill_parent"    xmlns:android="http://schemas.android.com/apk/res/android">           <ImageView android:id="@+id/icon"             android:layout_width="wrap_content"      android:layout_height="wrap_content">        </ImageView>        <TextView android:id="@+id/item"             android:layout_width="wrap_content" android:layout_height="wrap_content">        </TextView>        <TextView android:id="@+id/price"              android:layout_width="wrap_content"      android:layout_height="wrap_content">        </TextView></LinearLayout>实现的效果 图片 Chicken Sandwich $3.99 

更多相关文章

  1. SpringBoot 2.0 中 HikariCP 数据库连接池原理解析
  2. 一句话锁定MySQL数据占用元凶
  3. Android使用getIdentifier()方法根据资源名来获取资源id
  4. android 利用java反射调用系统类的隐藏方法
  5. Android入门之四大组件
  6. Android(安卓)Studio 新建项目的R文件丢失的解决方法
  7. Android(安卓)View (4) View的绘制过程
  8. 二、Android(安卓)NDK编程预备之Java jni入门Hello World
  9. Android获取app应用程序大小的方法

随机推荐

  1. Android转场动画windowAnimation和Activi
  2. Android中SQLiteOpenHelper类的onUpgrade
  3. Studio 1.5模拟器启动错误android/metric
  4. HashMap 的 7 种遍历方式与性能分析!(强烈
  5. Android引用百度定位API第三方组件后导致
  6. 开发Android平板电脑程序不能全屏显示问
  7. Android消息通知
  8. Android 桌面组件
  9. Android 抽屉侧滑效果
  10. Android默认给予USB读写权限,去掉授权对话