Hello.
I have a database with 3 tables in it. They are "Projects", "Contacts" and "Project Types". I have a UI for creating (adding a record) a new project which adds a record to the "Projects" table. In that UI, I have a button to fetch Contact Names from the "Contacts" table which in turn displays a ListView of all Contacts. When the name is selected, it should go back to the Projects UI and the name has to be displayed in the EditText. However, i keep getting this in the EditText: android.database.sqlite.SQLiteCursor@43d34310
Am attaching code snippets to the post for advice.
The ListActivity onCreate() code:
public class ContactsList extends ListActivity {
DBAdapter dbContactList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editproject_list);
dbContactList = new DBAdapter(this);
// Pull the data from the database
String[] fields = new String[] { dbContactList.TABLE_CON_NAME };
int[] views = new int[] { android.R.id.text1 };
Cursor c = dbContactList.getAllContacts();
startManagingCursor(c);
// Set the ListView
ListAdapter prjName = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, c, fields, views);
setListAdapter(prjName);
dbContactList.close();
}
The onListItemClick code:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Intent selectedContact = new Intent();
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
selectedContact.putExtra("selectedcontact", keyword);
setResult(RESULT_OK, selectedContact);
finish();
}
And the Projects UI code to start the activity for the ListView and for getting the results:
public void onClickContactPicker(View target)
{
Intent contactPicker = new Intent(this, com.dzinesunlimited.quotetogo.ContactsList.class);
startActivityForResult(contactPicker, contact);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String contact = data.getExtras().getString("selectedcontact").toString();
((EditText)findViewById(R.id.txtProjectContacts)).setText(contact);
}
This is the query() from the DB Adapter
public Cursor getAllContacts()
{
Cursor cursor = null;
try
{
cursor = db.query(TABLE_CONTACTS, new String[] {
TABLE_CON_ID, TABLE_CON_NAME, TABLE_CON_EMAIL,
TABLE_CON_EXPERTISE, TABLE_CON_CHARGES},
null,
null,
null,
null,
null);
}
catch (SQLiteException e)
{
Log.e("Database.addRow", "Database Error: " + e.toString());
e.printStackTrace();
}
return cursor;
}
Please advice on the solution to this.
Thanks in advance.