Hello,
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:
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);
}
This is part of the onCreate() from ListViewContacts, this retrieves
the contact from ContactList and adds it to the ListView:
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);
}
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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---