public class contacts extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
setContentView(R.layout.con_main);
}catch(Exception e){
Toast.makeText(this,e.toString(),Toast.LENGTH_LONG).show();
}
try{
Uri allContacts = Uri.parse("content://contacts/people");
Cursor c1 = managedQuery(allContacts,null,null,null,null);
Cursor c = managedQuery(allContacts,null,null,null,null);
String number = c.getString(c.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
String[] columns = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,number
};
int[] views = new int[] {R.id.contactName};
SimpleCursorAdapter adapter =new SimpleCursorAdapter(this, R.layout.con_main, c1, columns, views);
this.setListAdapter(adapter);
}catch(Exception e){
Toast.makeText(this,e.toString(),Toast.LENGTH_LONG).show();
}
}
}
答案 0 :(得分:1)
这是因为您为适配器放置了一个视图:
int[] views = new int[] {R.id.contactName};
您必须为数字添加另一个TextView
答案 1 :(得分:0)
你需要像这样定义视图
int[] views = new int[] { R.id.contactName, R.id.contactNumber };
这意味着您需要在con_main布局文件中包含2个textview