android listview设置数据问题
List<String>contactList=newArrayList<String>();contactListView=(ListView)findViewById...
List<String> contactList=new ArrayList<String>();
contactListView = (ListView) findViewById(R.id.lv_contact);//绑定控件
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, contactList);//设置接口
contactListView.setAdapter(adapter);//绑定接口
readContact();//方法,未列出,这个方法里面设置contactList的内容
为什么设置contactList内容的方法最后执行,但是运行显示listview中会显示contactList的数据
readContact()方法如下:
private void readContact() {
Cursor cursor = null;
cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
null, null);
while (cursor.moveToNext()) {
String name = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contactList.add(name + " " + number);
}
cursor.close();
} 展开
contactListView = (ListView) findViewById(R.id.lv_contact);//绑定控件
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, contactList);//设置接口
contactListView.setAdapter(adapter);//绑定接口
readContact();//方法,未列出,这个方法里面设置contactList的内容
为什么设置contactList内容的方法最后执行,但是运行显示listview中会显示contactList的数据
readContact()方法如下:
private void readContact() {
Cursor cursor = null;
cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
null, null);
while (cursor.moveToNext()) {
String name = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contactList.add(name + " " + number);
}
cursor.close();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询