0

ExpandableListAdapter を使用して ExpandableListView を表示しようとしています。私はいくつかの問題を抱えています。最初は、次のように UNION を使用していました。

    Cursor cur = db.rawQuery("select ig._id, ig.nombre, 0 tipo from InteresGrupo ig where ig.nombre<>'General' "+
                             "union "+
                             "select i._id, i.nombre, 1 tipo from Interes i "+
                             "inner join InteresGrupo g on i.interesGrupo=g._id "+
                             "where g.nombre='General' "+
                             "order by ig.nombre", null);

次の例外がスローされました。

Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

SQLite エディタで試してみると、SQL は完全に機能していました。最後に、「UNION」を「UNION ALL」に変更して機能させることができました(理由はまだわかりません)。

次の問題 (まだ未解決) は、要素を並べ替えようとしたときに発生しました。次の文を使用しました。

    Cursor cur = db.rawQuery("select ig._id, ig.nombre, 0 tipo from InteresGrupo ig where ig.nombre<>'General' "+
                             "union all "+
                             "select i._id, i.nombre, 1 tipo from Interes i "+
                             "inner join InteresGrupo g on i.interesGrupo=g._id "+
                             "where g.nombre='General' "+
                             "order by 2", null);

再び同じ例外。SQL 文は SQLite エディタで再びうまく機能するので、アダプターでの SQL 文の使用にはいくつかの制限があるはずだと思います。

アダプターのメソッドが呼び出される前に例外がスローされるため、アダプター内のコードとは関係なく、SQL 文だけです (推測します)。次の 3 行の 3 番目に発生します。

    ExpandableListView epView = (ExpandableListView)findViewById(R.id.lvIntereses);
    mAdapter = new MyExpandableListAdapter(cur, this);
    epView.setAdapter(mAdapter);

誰でもヒントを与えることができますか?

前もって感謝します。

4

1 に答える 1

0
"union all"+"select ....

結果はunion allselect..

union all と select の間にスペースが必要です

元。"union all " + "select ....

あるいは単に"union all select ..."

于 2013-03-12T19:52:21.807 に答える