在此代码中使用游标时获取运行时异常

时间:2014-01-04 10:36:17

标签: android listview cursor

我的onitemclick部分代码是.....

我有三列id标题和notetext,当我从listview点击标题时,我只想显示我的sqlite数据库列(notetext)中的文本。

lv.setOnItemClickListener(new OnItemClickListener()
{

 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
    {
Cursor cursor = (Cursor)arg0.getItemAtPosition(arg2); // i m getting error here

String product = cursor.getString(cursor.getColumnIndex("notetext"));

Intent myintent = new Intent(getApplicationContext(),view1.class);

myintent.putExtra("product", product);

startActivity(myintent);

   }
});

2 个答案:

答案 0 :(得分:0)

检查此链接,希望这有助于您解决问题。

  

http://www.mysamplecode.com/2012/07/android-listview-cursoradapter-sqlite.html

答案 1 :(得分:0)

试试这段代码

  cursor.moveToPosition(position);
  String product = cursor.getString(cursor.getColumnIndex("notetext"));