I'd like to add my selected PhonesContacts(currently 2 strings) to a listview. Currently im doing this: (Name and PhoneNo are written to the textview) This are the strings that i'd like to display in a list.
Its working with textView already but when i want to add a second one it overwrites the first one. Thats why i'd like to show it in a list.
How can i change this to listview?
I tried creating an ArrayList and passing the string to this ArrayList but this hasn't been working.
private void contactPicked(Intent data) {
Cursor cursor = null;
try {
String phoneNo = null ;
String name = null;
// getData() method will have the Content Uri of the selected contact
Uri uri = data.getData();
//Query the content uri
cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
// column index of the phone number
int phoneIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
// column index of the contact name
int nameIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
phoneNo = cursor.getString(phoneIndex);
name = cursor.getString(nameIndex);
// Set the value to the textviews
textView1.setText(name);
textView2.setText(phoneNo);
} catch (Exception e) {
e.printStackTrace();
}
}
For the listview i created a
private ListView listView;
and used it in my OnCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_view);
listView = (ListView) findViewById(R.id.listView);