2014-06-22 4 views
0

안녕 얘들 아 나는 질문이있다. 어떻게 데이터베이스를 뒤에서 읽을 수 있었 을까? 이 내 방법은 파일을 읽기위한 것입니다! 어떻게 SQL 데이터베이스를 뒤로 읽을 수 있습니까?

Cursor cursor = myDb.getAllRows(); 

// Allow activity to manage lifetime of the cursor. 
// DEPRECATED! Runs on the UI thread, OK for small/short queries. 
startManagingCursor(cursor); 

// Setup mapping from cursor to view fields: 
String[] fromFieldNames = new String[] 
     {DBAdapter.KEY_KALO, DBAdapter.KEY_HYDRATE, DBAdapter.KEY_FAT, DBAdapter.KEY_PROTEIN ,DBAdapter.KEY_CAL}; 
int[] toViewIDs = new int[] 
     {R.id.item_Kalorien,  R.id.item_KG_in_g,   R.id.item_F_in_g,  R.id.item_P_in_g,R.id.item_cal}; 

// Create adapter to may columns of the DB onto elemesnt in the UI. 
SimpleCursorAdapter myCursorAdapter = 
     new SimpleCursorAdapter(
       this,  // Context 
       R.layout.item_tagebuch, // Row layout template 
       cursor,     // cursor (set of DB records to map) 
       fromFieldNames,   // DB Column names 
       toViewIDs    // View IDs to put information in 
       ); 

// Set the adapter for the list view 
ListView myList = (ListView) findViewById(R.id.listView1); 
myList.setAdapter(myCursorAdapter); 

이 도움을 주셔서 감사합니다 :)를

+0

@Josef E. 당신이 도움이 될 수 제품 설명에 쿼리 방법의 konstructor을 변경했다 나 여기??) – Strik3r

답변

관련 문제