如何用字符串定义游标值?

发布于 2024-10-23 19:22:33 字数 1222 浏览 1 评论 0原文

我有这个字符串 “android.database.sqlite.SQLiteCursor@44defce0” 我如何用该字符串创建光标值?

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub
    input = auto.getText().toString();//this class use implements TextWatcher

    KamusDbAdapter x = new KamusDbAdapter(getApplicationContext());
    x.open();
    Cursor cur = x.getCall(input, selection);
    x.close();//getCall() to get cursor from sqlite result

    String[] displayFields = new String[] {"word", "meaning"};
    //word & meaning are fields inside the table
    int[] displayViews = new int[] { android.R.id.text1,android.R.id.text2 };

    auto.setAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cur,displayFields, displayViews));

}

onitem 单击调用

auto.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            main = auto.getText().toString();
            result.setText(main);
            auto.setText("");
        }
    });

i have this string
"android.database.sqlite.SQLiteCursor@44defce0"
how can i make a cursor value with that string?

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub
    input = auto.getText().toString();//this class use implements TextWatcher

    KamusDbAdapter x = new KamusDbAdapter(getApplicationContext());
    x.open();
    Cursor cur = x.getCall(input, selection);
    x.close();//getCall() to get cursor from sqlite result

    String[] displayFields = new String[] {"word", "meaning"};
    //word & meaning are fields inside the table
    int[] displayViews = new int[] { android.R.id.text1,android.R.id.text2 };

    auto.setAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cur,displayFields, displayViews));

}

onitem click invoke

auto.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            main = auto.getText().toString();
            result.setText(main);
            auto.setText("");
        }
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假扮的天使 2024-10-30 19:22:33

不太确定您的代码与您的问题有什么关系,但您可以使用 MatrixCursor 在代码中创建光标。例如:

  MatrixCursor cursor = new MatrixCursor(new String[] {"column1"});
  cursor.addRow(new String[] {"android.database.sqlite.SQLiteCursor@44defce0"});

这将为您提供一个游标对象,其中包含名为“column1”的单列,以及包含您提到的字符串的单行。如果您愿意,可以将该游标传递给需要游标的适配器。

Not quite sure what your code has to do with your question, but you can use MatrixCursor to create cursors in code. For example:

  MatrixCursor cursor = new MatrixCursor(new String[] {"column1"});
  cursor.addRow(new String[] {"android.database.sqlite.SQLiteCursor@44defce0"});

This will give you a cursor object with a single column named "column1", with a single row containing the string you mention. This cursor can then be passed to an adapter expecting a cursor, if you wish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文