2010-06-18 2 views
5

커서가 올바르게 작동하는 방법을 설명 할 수 있습니까? 또는 코드의 다음 부분의 흐름? 나는 이것이 하위 활동이고 모든 것이 Cursor가 정확히 어떻게 작동하는지 이해하지 못했다는 것을 알고 있습니다.누군가 Cursor를 Android에서 설명해 주실 수 있습니까?

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

감사합니다.

답변

3

커서는 데이터베이스 리소스에서 생성 된 목록/포인터와 같습니다.

당신은 당신은 연락처를 조회

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

를 실행하면 (PHP에서는 mysql_query()에서 $ 입술처럼 생각은)는 결과의 레코드에 대한 포인터가있는 커서를 반환

그런 다음이 커서에서 어댑터를 작성합니다. 어댑터는 소스에서 가져온 결과의 오브젝트 레벨 표현이며, 이번에는 커서, 즉 데이터베이스의 레코드입니다. (PHP 용 어댑터에서 Smarty Templates 용 배열처럼 생각하면 배열은 어댑터입니다.)

setOnItemClickListener는 이벤트 기반 프로그래밍을 쉽게 이해할 수 있어야합니다.

관련 문제