gpt4 book ai didi

android - 搜索需要来自多个游标/表的数据

转载 作者:行者123 更新时间:2023-11-29 22:32:16 25 4
gpt4 key购买 nike

我仍在尝试在我的 Android 应用程序中实现搜索功能。到目前为止一切正常,尽管目前搜索只能查询一个表并显示该表的结果(它是一个使用 SimpleCursorAdapter 的 ListView)。

我想要的是能够搜索多个表,但我不确定如何将其全部放入一个游标或扩展 SimpleCursorAdapter 以实现多个游标。我看到有一个名为 CursorJoiner 的类,但我不确定我需要用它做什么。

谢谢!

我曾尝试制作自定义 cursor[] 适配器,但这没有返回任何内容,而且我的搜索结果为空白 - 谁能帮忙?

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);
}

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;

只是注意到它实际上并不是适配器没有返回任何内容,我的搜索 Activity 有问题...

最佳答案

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

如果您使用的是 SQLite,请在您的 SELECT 语句中实现一个 JOIN。如果您出于某种原因将 SQLite 包装在内容提供程序中,请公开另一个内容 Uri 并支持您的多表搜索。

关于android - 搜索需要来自多个游标/表的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3594917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com