大家好我在mItems.add()中遇到问题它需要参数int和Collection类型。我给参数作为int并传递一些字符串值。我不明白为什么添加时出错。
private List mItems; // ListView项目列表
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// initialize the items list
mItems = new ArrayList<ListViewItem>();
Resources resources = getResources();
DBHandler dbh = new DBHandler(getContext());
String friend_name, friend_status,friend_date_time,friend_fb_id;
String fb_url;
Cursor cursor = dbh.readAllFriends(dbh);
int a=0;
while(cursor.moveToNext()){
friend_name = cursor.getString(cursor.getColumnIndex(TableInfo.F_USER_NAME));
friend_status = cursor.getString(cursor.getColumnIndex(TableInfo.F_USER_STATUS));
friend_date_time = cursor.getString(cursor.getColumnIndex(TableInfo.F_DATE));
friend_fb_id = cursor.getString(cursor.getColumnIndex(TableInfo.F_FACEBOOK_ID));
fb_url="https://graph.facebook.com/"+friend_fb_id+"/picture?type=large";
mItems.add(a, fb_url,friend_name,friend_status,friend_date_time);
}
cursor.close();
答案 0 :(得分:1)
你做错了。喜欢
ListViewItem item =new ListViewItem(a, fb_url,friend_name,friend_status,friend_date_time);
mItems.add(item );
您应在ListViewItem
mItems ArrayList
对象
答案 1 :(得分:0)
在add()参数中应该是ListViewItem类型, 所以在add()中传递ListViewItem的引用。
答案 2 :(得分:0)
最后在你的while循环中进行以下更改
更改
mItems.add(a, fb_url,friend_name,friend_status,friend_date_time);
要
ListViewItem obj=new ListViewItem(a, fb_url,friend_name,friend_status,friend_date_time);
mList.add(obj);
在ListViewItem类中添加构造函数
ListViewItem(a, fb_url,friend_name,friend_status,friend_date_time);
{
}
希望这有帮助。