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

标签 android string cursor

我有这个字符串 “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("");
        }
    });

最佳答案

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

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

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

关于android - 如何用字符串定义游标值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5373694/

相关文章:

php - 用随机字符替换字符串中的每个数字

SQL Server - 游标

java - 改造返回空列表

android - 如何使用 Robotium 从其他进程运行 Activity

c - fork() 后数组改变值

r - 在不同顺序的字符串中查找字母

java - 列 '_id' 不存在,嵌套查询的

android - 自定义列表光标适配器在模拟器上的 bindView 崩溃——而不是在手机上

android - 如何在 Intent 中调用新 Activity 时使用变量?

android - 如何将editText宽度设置为一个字符