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

时间:2011-03-21 04:05:56

标签: 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("");
        }
    });

1 个答案:

答案 0 :(得分:4)

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

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

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