这是一个非常奇怪的问题。我直接贴代码:
package com.asim.contactspull;
public class Contact
{
private String name;
private String number;
public Contact(String sname, String snumber)
{
this.name = sname;
this.number = snumber;
}
}
以上是我的自定义类。以下是我的主要活动:
package com.asim.contactspull;
public class MainActivity extends Activity
{
ArrayList<Contact> contactList;
ListView contacts;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contactList = new ArrayList<Contact>();
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
while (phones.moveToNext())
{
Contact c = new Contact(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)), phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
Log.d("Contact: ", "" + c.toString());
contactList.add(c);
}
phones.close();
contacts = (ListView) findViewById(R.id.contacts);
ArrayAdapter<Contact> aa = new ArrayAdapter<Contact>(this, android.R.layout.simple_list_item_1, contactList);
contacts.setAdapter(aa);
}
}
当我运行上面的代码时,我在我的 ListView 中得到这样的条目:
com.asim.contactspull Contact@405206e8
我究竟做错了什么?