I want to see with the simplecursoradapter and the built-in ListView a list of my contacts showing their name,email and picture(all saved in sqlite)
having this code (notice that i'm not using the cursor, I'm using null beacuse I'm goig to provide the cursor later):
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);
}
and then:
@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();
}
}
if you notitce I provide the cursor inside a onPostExecute with the changeCursor, not in the begining, So my questions are: 1.-How can I use the viewBinder in this way??Images in SimpleCursorAdapter I want to add an image inside(int[] to = new int[] { R.id.contactTextView,R.id.emailTextView2,R.id.imageView1};//imageView1 is a ImageView) so in this way I can see name,email,image
Also my database have the following: fields:
"CREATE TABLE wholeContacts" +
"(_id integer primary key autoincrement," +
"name TEXT, email TEXT, +
"image BLOB);";
2.-I'ts a good practice to use the the sqlite to save pictures(inside database) if can contain almost 5000 records, but pictures are of 2.6kb(very small pictures)???? thanks