Can someone explain the cursor on the android?

Can anyone explain how the cursor works? Or a stream of the next piece of code? I know that this is a sub-activity and that’s all, but I didn’t understand how the cursor works.

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();
     }
});

Thank.

+5
source share
1 answer

The cursor is like a list / pointer created from a database resource. (In PHP, I think like $ res from mysql_query ())

At startup

managedQuery(data, null, null, null, null);

You request contacts, it returns a cursor, which is a pointer to records in the results

Then you create an adapter from this cursor. The adapter is a representation of the level of the object from the results taken from the source, this time it is the cursor, as well as records from the database. (In PHP, an adapter is considered an array for Smarty templates, an array is an adapter)

SetOnItemClickListener , .

+3

All Articles