Can someone please explain Cursor in android ?

Posted by Prabhat on Stack Overflow See other posts from Stack Overflow or by Prabhat
Published on 2010-06-18T12:08:49Z Indexed on 2010/06/18 12:13 UTC
Read the original article Hit count: 209

Filed under:

Can some one explain how the cursor exactly works ? Or the flow of the following part of the code ? I know that this is sub activity and all but I did not understand how Cursor works exactly.

final Uri data = Uri.parse("content://contacts/people/");
final Cursor c = managedQuery(data, null, null, null, null);
String[] from = new String[] { People.NAME };
int[] to = new int[] { R.id.itemTextView };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.listitemlayout, c, from, to);
ListView lv = (ListView) findViewById(R.id.contactListView);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
     public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { 

          c.moveToPosition(pos);
          int rowId = c.getInt(c.getColumnIndexOrThrow("_id"));
          Uri outURI = Uri.parse(data.toString() + rowId);
          Intent outData = new Intent();
          outData.setData(outURI);
          setResult(Activity.RESULT_OK, outData);
          finish();
     }
});

Thanks.

© Stack Overflow or respective owner

Related posts about android