0

LoaderManager.LoaderCallbacks Cursor 클래스를 구현하는 활동이 있습니다. SQlite에서 데이터를 가져 오는이 기능이 있습니다.SimpleCursorAdapter에서 커서 가져 오기

@Override 
public Loader<Cursor> onCreateLoader(int id, Bundle args) { 
    switch (id) { 
     case ITEM_LOADER_ID: 
      // The uri points to Item, which is the items in the inventory 
      Uri uri = InventoryContract.Item.contentUriWithAccount(mCloverAccount); 
      String sortOrder = InventoryContract.Item.NAME; 

      String selection = ""; 

      try { 

       selection = InventoryContract.ItemColumns.CODE; 

      catch (Exception e){ 
       Log.e("Error",e.toString()); 
      } 
      return new CursorLoader(HomeActivity.this, uri, null, selection, null, sortOrder); 
     default: 
      // An invalid id was passed in 
    } 
    throw new IllegalArgumentException("Unknown Loader ID"); 
} 

은 내가 SimpleCursorAdapter

SimpleCursorAdapter adapter = new SimpleCursorAdapter(
      this, 
      android.R.layout.simple_list_item_2, 
      null, 
      new String[]{InventoryContract.Item.NAME, InventoryContract.Item.PRICE_TYPE}, 
      new int[]{android.R.id.text1, android.R.id.text2}, 
      0 
    ); 

이 기능과 데이터를 가져 오는 것입니다을 가지고 있지만 나는 모든 정보를 검색 후 실행 목록에 저장할 수 있도록 커서를 싶어. 커서를 가져 오기위한 모든 관련 링크를 검색하고 코드를 찾았습니다.

Cursor c = adapter.getCursor(); 
    try { 

     int i = 0; 
     while (c.moveToNext()){ 
      Log.e("In Log Cursor",c.getString(i)); 
      i++; 
     } 
     c.close(); 
    } 
    catch (Exception e){ 
     Log.e("Error",e.toString()); 
    }    

null 커서가 표시됩니다. 그 데이터를 가져 와서 추가 조작을 위해 맞춤형 어댑터를 만들고 싶습니다. 제가 SQlite에서 그 데이터를 얻고 다른 방법으로 그것을 찾을 수 있도록 도와 주시고 제가 가져온 후에 그것을 사용할 수있는 List로 저장하고 RecyclerView에서 저장할 수있게하십시오. 미리 감사드립니다.

+0

당신이 사용자 정의 어댑터를 필요가없는 onloadFinshed 방법에서 단계를 구현할 수 있습니다. github.com/Shywim/127f207e7248fe48400b) 어댑터 대신 – pskink

+0

CursorRecyclerAdapter (커서 커서)이 함수에서 커서를 전달해야하지만 해당 커서에서 얻을 수있는 위치는 무엇입니까? – Awais

+0

http://www.grokkingandroid.com/using-loaders-in-android/#how_to_deal_with_cursoradapters 참조 – pskink

답변

0

나는 그것이 오래된 게시물이라고 생각하지만 그것이 누군가를 도울 수 있다고 생각했습니다. // 요점 : 당신은 단지`SimpleCursorAdapter`를 사용하고`RecyclerView` 사용 [이] (HTTPS에 데이터를 표시 할 경우, 그는

public void onLoadFinished(Loader<Cursor> loader, Cursor data) { 
    adapter.swapCursor(data); 
     /* 
     data.moveToFirst(); 

    if (data.getCount() != 0) { 
     for (int i = 0; i < data.getCount(); i++) { 
      String s = data.getString(data.getColumnIndex(column no)); 
      data.moveToNext(); 
     } 
    } 


}