2013-10-17 69 views
1

的Android simplecursoradapter我想看到的simplecursoradapter和我交往的內置的ListView列表中顯示他們的姓名,電子郵件及圖片(所有保存在源碼)與ImageView的

有這個代碼(請注意,我」米不使用光標,我使用的是空怎麼一回事,因爲我goig提供後光標):

private CursorAdapter contactAdapter; 
    @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      contactList = getListView(); 
      contactList.setOnItemClickListener(viewContactListener);  


      String[] from = new String[] { "name","email","image" }; 
      int[] to = new int[] { R.id.contactTextView,R.id.emailTextView2,R.id.imageView1};//imageView1 is a ImageView 
      contactAdapter = new SimpleCursorAdapter(
      MyFirstActivity.this, R.layout.contact_list_item, null, from, to); 

      setListAdapter(contactAdapter); 



     } 

然後:

@Override 
    protected void onResume() 
    { 
     super.onResume(); 
     new StartPopulate().execute((Object[]) null); 
    } 


private class StartPopulate extends AsyncTask<Object, Object, Cursor> 
    { 
     MyDatabaseConnector myDatabaseConnector = 
     new MyDatabaseConnector(myActivity.this); 

     // perform the database access 
     @Override 
     protected Cursor doInBackground(Object... params) 
     { 
     myDatabaseConnector.open(); 

     return databaseConnector.getAllContacts(); //it is a cursor where I have the fields which I want to return 
     } 


     @Override 
     protected void onPostExecute(Cursor result) 
     { 
     contactAdapter.changeCursor(result); 
     myDatabaseConnector.close(); 
     } 
    } 

如果你notitce我提供內部AO光標nPostExchange與changeCursor,而不是在開始,所以我的問題是:1.如何使用viewBinder這樣? Images in SimpleCursorAdapter 我想添加一個圖像裏面(int [] to = new int [] {R.id.contactTextView,R.id.emailTextView2,R.id.imageView1}; // imageView1是一個ImageView) 所以在這個這樣我可以看到的姓名,電子郵件,圖像

而且我的數據庫有以下幾點:字段:

"CREATE TABLE wholeContacts" + 
      "(_id integer primary key autoincrement," + 
      "name TEXT, email TEXT, + 
      "image BLOB);"; 

2-I'ts一個很好的做法,使用SQLite的照片的保存(內部數據庫)如果可以包含近5000條記錄,但圖片是2.6kb(很小的圖片)? 感謝

回答

0

使用BitmapFactory.decodeByteArray其中字節陣列從Cursor.getBlob取()