Android 要启用从自定义适配器到ListView的详细信息传输,我缺少什么?
我正在从Android 要启用从自定义适配器到ListView的详细信息传输,我缺少什么?,android,listview,android-asynctask,custom-adapter,Android,Listview,Android Asynctask,Custom Adapter,我正在从NewContact.java中的doInBackground向我的自定义适配器(SelectPhoneContactAdapter)传输尽可能多的ListView信息,因为我已经阅读了尽可能多的逻辑信息 我的doInBackground中确实有大部分代码,它工作正常,但现在使用自定义适配器中的代码,我的ListView显示为空。你能告诉我需要在我的doInBackground中放些什么才能让它工作吗 我的应用程序运行时没有错误,当使用System.out.print进行调试时我可以在自
NewContact.java
中的doInBackground
向我的自定义适配器(SelectPhoneContactAdapter
)传输尽可能多的ListView
信息,因为我已经阅读了尽可能多的逻辑信息
我的doInBackground
中确实有大部分代码,它工作正常,但现在使用自定义适配器中的代码,我的ListView
显示为空。你能告诉我需要在我的doInBackground
中放些什么才能让它工作吗
我的应用程序运行时没有错误,当使用System.out.print进行调试时
我可以在自定义适配器中看到我的变量有贵重物品,因此它在列表视图中不应为空
这是我的NewContact.java
,它包含列表视图
:
// Load data in background
class LoadContact extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
//selectPhoneContacts is an empty array list that will hold our SelectPhoneContact info
selectPhoneContacts = new ArrayList<SelectPhoneContact>();
listView = (ListView) findViewById(R.id.listviewPhoneContacts);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
adapter = new SelectPhoneContactAdapter(selectPhoneContacts, NewContact.this);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
}
}
@Override
protected void onResume() {
super.onResume();
LoadContact loadContact = new LoadContact();
loadContact.execute();
}
您没有在数组列表中添加任何数据,请在doInBackground方法中检查它
在将适配器设置到列表视图之前,必须在数组列表中添加一些数据
示例代码
在选择Phone Contacts
中添加一些数据,如下所示:
@Override
protected Void doInBackground(Void... voids) {
//selectPhoneContacts is an empty array list that will hold our SelectPhoneContact info
selectPhoneContacts = new ArrayList<SelectPhoneContact>();
// add some data in to your list view here
SelectPhoneContact model= new SelectPhoneContact();
model.setPhone("123456789");
selectPhoneContacts.add(model);
listView = (ListView) findViewById(R.id.listviewPhoneContacts);
return null;
}
@覆盖
受保护的空位背景(空位…空位){
//selectPhoneContacts是一个空数组列表,用于保存SelectPhoneContact信息
选择PhoneContacts=new ArrayList();
//在此列表视图中添加一些数据
SelectPhoneContact model=新建SelectPhoneContact();
手机型号(“123456789”);
选择PhoneContacts.add(型号);
listView=(listView)findViewById(R.id.listviewPhoneContacts);
返回null;
}
您没有在数组列表中添加任何数据,请在doInBackground方法中检查它
在将适配器设置到列表视图之前,必须在数组列表中添加一些数据
示例代码
在选择Phone Contacts
中添加一些数据,如下所示:
@Override
protected Void doInBackground(Void... voids) {
//selectPhoneContacts is an empty array list that will hold our SelectPhoneContact info
selectPhoneContacts = new ArrayList<SelectPhoneContact>();
// add some data in to your list view here
SelectPhoneContact model= new SelectPhoneContact();
model.setPhone("123456789");
selectPhoneContacts.add(model);
listView = (ListView) findViewById(R.id.listviewPhoneContacts);
return null;
}
@覆盖
受保护的空位背景(空位…空位){
//selectPhoneContacts是一个空数组列表,用于保存SelectPhoneContact信息
选择PhoneContacts=new ArrayList();
//在此列表视图中添加一些数据
SelectPhoneContact model=新建SelectPhoneContact();
手机型号(“123456789”);
选择PhoneContacts.add(型号);
listView=(listView)findViewById(R.id.listviewPhoneContacts);
返回null;
}
您没有在数组列表中添加任何数据在doInBackground方法中检查您没有在数组列表中添加任何数据在doInBackground方法中检查我还建议您交换这两行适配器。notifyDataSetChanged();setAdapter(适配器)代码>使它们像这样listView.setAdapter(adapter);adapter.notifyDataSetChanged()代码>@Nilesh Rathod我的客户适配器中有电话号码。因此,看起来我必须将电话号码的字符串数组传递给我的NewContact活动,在该活动中将电话号码单独提取为字符串,称为phoneNumberofContact,然后model.setPhone(phoneNumberofContact)?@CHarris在将适配器设置到列表视图之前,您必须在数组列表中添加一些dtaa。我还建议您交换这两行adapter.notifyDataSetChanged();setAdapter(适配器)代码>使它们像这样listView.setAdapter(adapter);adapter.notifyDataSetChanged()代码>@Nilesh Rathod我的客户适配器中有电话号码。因此,看起来我必须将电话号码的字符串数组传递给我的NewContact活动,在该活动中将电话号码单独提取为字符串,称为phoneNumberofContact,然后model.setPhone(phoneNumberofContact)?@CHarris在将适配器设置到列表视图之前,必须在数组列表中添加一些dtaa