开发者

Search requires data from multiple cursors/tables

开发者 https://www.devze.com 2023-01-14 02:40 出处:网络
I\'m still trying to implement a search function into my Android app. So far it\'s going ok, although currently the search can only query one table and display the results for this table (its a ListVi

I'm still trying to implement a search function into my Android app. So far it's going ok, although currently the search can only query one table and display the results for this table (its a ListView using SimpleCursorAdapter).

What I want is to be able to search multiple tables, but I'm not sure how to get this all into one cursor or extend the SimpleCursorAdapter to implement multiple cursors. I see there is a class called CursorJoiner, but I'm not sure what I need to do with it.

Thanks!

I have tried to make a custom cursor[] adapter, but this doesn't return anything and my search results are blank- can anyone help?

public class SearchCursorAdapter extends SimpleCursorAdapter {

private int currentCursor;
private int curPosition = 0;
private int total = 0;
private Cursor[] curs = null;
private Context cont;

public SearchCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) {

    super(context, layout, c, from, to);
    total = c.getCount();

}

public SearchCursorAdapter(Context context, int layout, Cursor[] c,
        String[] from, int[] to) {

    super(context, layout, null, from, to);
    int l = c.length;
    for (int i = 0; i < l; i++) {

        total += c[i].getCount();

    }
    curs = c;
    currentCursor = 0;
    cont = context;
}

@Override
public View getView(int position, View view, ViewGroup parent) {

    if (currentCursor == curs.length)
        return null;

    if (curs == null) {

        //normal shiz

    }
    else {

        Cursor c = curs[currentCursor];
        c.moveToPosition(curPosition);

        if (c.isAfterLast()) {

            currentCursor++;
            c = curs[currentCursor];
            curPosition = 0;
            c.moveToPosition(curPosition);

        }

        if (view == null) {
            LayoutInflater vi = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.search_row, null);
        开发者_如何学Go}

        TextView t1 = (TextView)view.findViewById(R.id.rowitem_text1);
        TextView t2 = (TextView)view.findViewById(R.id.rowitem_text2);

        t1.setText(c.getString(1));
        t2.setText("Testing");

        curPosition++;

    }

    return view;

just noticed that it's not actually the adapter returning nothing, there's something wrong with my searchactivity...


What I want is to be able to search multiple tables, but I'm not sure how to get this all into one cursor or extend the SimpleCursorAdapter to implement multiple cursors

If you are using SQLite, implement a JOIN in your SELECT statement. If you have wrapped SQLite in a content provider for some reason, expose another content Uri and support for your multi-table search.

0

精彩评论

暂无评论...
验证码 换一张
取 消