代码之家  ›  专栏  ›  技术社区  ›  Andrew Ebling

在ListActivity中显示SQL联接的结果

  •  1
  • Andrew Ebling  · 技术社区  · 14 年前

    我创建了一个光标:

    Cursor cursor = db.rawQuery(LIST_JOIN_SQL, null);
    

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
    R.layout.item, cursor, FROM, TO);
    

    其中FROM和TO定义为:

    private static String[] FROM = { "name", };
    private static int[] TO = { R.id.name, };
    

    你推荐什么方法?我只能使用android1.6api。

    2 回复  |  直到 14 年前
        1
  •  2
  •   Pentium10    14 年前

    _ID

    select col1 as _id from table
    
        2
  •  1
  •   Dan Lew    14 年前

    要使用CursorAdapter(或其任何子类),您需要有“\u id”列; it's explicitly stated in the documentation . 这是因为CursorAdapter大量使用此列。

    1. BaseAdapter )它本质上是一个CursorAdapter,但不需要\u id字段。

    我怀疑如果您控制数据库,那么#1将更容易执行,但是如果您无法更改数据库的模式,那么您必须执行#2。