I have a ListView (ListViewContacts) and another ListView (ContactList).
When I click on a Button in ListViewContacts I get ContactList, when I select/click a contact in ContactList, this contact is added to the list in ListViewContacts.
This scenario above is what I would like to achieve, though I haven't found the right way to do this.
This is the onListItemClick code for ContactList, this starts the Activity ListViewContact and also gives the clicked contact:
Using java Syntax Highlighting
- protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- Intent intent = new Intent(ContactList.this, BlablaActivity.class);
- Uri person = ContentUris.withAppendedId(People.CONTENT_URI, id);
- intent.setData(person);
- startActivity(intent);
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
This is part of the onCreate() from ListViewContacts, this retrieves the contact from ContactList and adds it to the ListView:
Using java Syntax Highlighting
- if(getIntent().getData() != null) {
- Uri data = getIntent().getData();
- Cursor addedContactCursor = getContentResolver().query(data, null, null, null, null);
- startManagingCursor(addedContactCursor);
- String[] name = new String[]{People.NAME, People.NUMBER};
- int[] to = new int[]{R.id.nametext, R.id.numbertext};
- adapter = new SimpleCursorAdapter(this,R.layout.contact_row, addedContactCursor, name, to);
- ListView listView = (ListView) findViewById(R.id.addedcontactslist);
- listView.setAdapter(adapter);
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
The problem here is that only 1 contact is added to the list each time, which is the last one that has been clicked on within the ContactList. The code speaks for it self. I assume this happens because a new SimpleCursorAdapter is initiated every time.
What is the best way of adding these contacts, so that the ListViewContacts keeps remembering all contacts and not only the last one that is added? Thanks in advace.

