Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用union子句在使用ExpandableListAdapter时引发异常_Android_Expandablelistadapter - Fatal编程技术网

Android 使用union子句在使用ExpandableListAdapter时引发异常

Android 使用union子句在使用ExpandableListAdapter时引发异常,android,expandablelistadapter,Android,Expandablelistadapter,我正在尝试使用ExpandableListAdapter显示ExpandableListView。我有几个问题。第一种是使用UNION,如下所示: Cursor cur = db.rawQuery("select ig._id, ig.nombre, 0 tipo from InteresGrupo ig where ig.nombre<>'General' "+ "union "+

我正在尝试使用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);
SQL在SQLite编辑器中运行得非常好。最后,我可以将“联合”改为“全体联合”(我仍然不知道为什么)

下一个问题(仍然没有解决)出现在我试图对元素排序时。我用了下一句话:

    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);
谁能给小费

提前谢谢

"union all"+"select ....
结果显示
union allselect

在“全部联合”和“选择”之间需要一个空格

例如,
“联合所有”+“选择…”


或者只是
“联合所有选择…”

另外,你有“订单2”。不确定你想在那里做什么。对不起,dymmeh。编辑代码来发布我的答案我把“联合所有”+“选择…”放在了我的真实代码中,但这个句子是正确的(我编辑我的问题是为了纠正这个错误)。问题不在于这句话,因为发生这种情况时会出现sql sintax错误。我正在尝试ExpandableListView以该顺序显示元素(按“nombre”)。如果没有“order by”子句,一切正常,但显示的列表没有顺序。@Martillador81为什么有“order by 2”?这也是一个拼写错误吗?应该是吗order by ig.nombre“?“order by 2”应该与“order by ig.nombre”相同(它表示按第2列排序)。当我在Firefox SQLite管理器中进行查询时,它会起作用。我在其他DBMS中广泛使用了这种表示法。
    ExpandableListView epView = (ExpandableListView)findViewById(R.id.lvIntereses);
    mAdapter = new MyExpandableListAdapter(cur, this);
    epView.setAdapter(mAdapter);
"union all"+"select ....