0

ExpandableListView に問題があります。私が望むのは、各グループが一意ではない列「bond」からのものであることですが、グループを一意にする必要があります(つまり、「bond」の各値には1つのグループのみを含める必要があります)。グループ内の各値には、表示する必要がある他の列のデータがあります。問題は、SQL DISTINCT 演算子を 1 つの列で使用する (そして getChildrenCursor() が IllegalStateException をスローする) か、DISTINCT 演算子を使用せずに各グループを複製できるように見えることです。

誰でもこれの修正を提案できますか?

public void onCreate(Bundle saved) {

    super.onCreate(saved);

    DatabaseHelper dh = new DatabaseHelper(this);
    dh.openDataBase();
    db = dh.getReadableDatabase();

    String query = "SELECT DISTINCT bond FROM spectro";

    Cursor c = db.rawQuery(query, null); //throws exception when group opened
    //Cursor c = db.query("spectro", new String[] { "_id", "name", "bond", ir },
        //null, null, null, null, null) - gives duplicate groups

    ExpandableListAdapter a = new IRCursorAdapter (this,
            c, android.R.layout.simple_expandable_list_item_1, new String[] { "bond" },
            new int[] { android.R.id.text1 }, R.layout.row_doubleend,
            new String[] { "name", "ir" }, new int[] { R.id.double_item1, R.id.double_item2 });

    this.setListAdapter(a);


}

protected class IRCursorAdapter extends SimpleCursorTreeAdapter {

    public IRCursorAdapter(Context context, Cursor cursor, int groupLayout,
            String[] groupFrom, int[] groupTo, int childLayout,
            String[] childFrom, int[] childTo) {
        super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom,
                childTo);
    }

    @Override
    protected Cursor getChildrenCursor(Cursor groupCursor) {

        Cursor c = db.query("spectro", new String[] {"_id", "name", "bond", "ir"},
                "bond=?", new String[] { groupCursor.getString(0) }, null, null, null);

        startManagingCursor(c);
        return c;
    }


};

これが私のテーブルの外観です-絆は私がユニークにしたいものです:

_id | 名前 | 絆 | ir
1 | 名前 1 | ボンド1 | ir 1
2 | 名前 2 | ボンド1 | ir 2
3 | 名前 3 | ボンド 2 | ir 3
4 | 名前 4 | ボンド3 | ir 4

これが特に明確でない場合は申し訳ありませんが、助けてくれてありがとう!

4

1 に答える 1

0

明確な演算子を誤用していると思います。IT は Bond1、Bond2、Bond3 のみを返し、それだけです。正しいカーソルを生成するには、複合結合ステートメントを作成する必要があります。子を正しく指定していないため、そこにあるものは常にエラーをスローします。次に、(生のクエリではなく) クエリを使用し、そこでパラメーターを指定します。

例 db.query(true, "spectro", new String[]{"bond"}, null,null,...)

また、Group From -->To パラメータと Children From --> to パラメータが正しいことを確認する必要があります。

于 2010-11-30T16:15:31.687 に答える