我正在从 facebook 获取朋友列表并在列表视图中填充它工作正常但现在我正在尝试添加进度条直到列表视图填充但出现异常我已经尝试搜索但没有找到我的问题的解决方案,这是我的代码:
public class FriendsProgress extends AsyncTask<Object, Void, Boolean>
{
@Override
protected Boolean doInBackground(Object... Params)
{
try
{
getFriendList();
friendAdapter = new FriendAdapter(Friends.this, R.layout.activity_friends, friendsList);
Friends.this.runOnUiThread(new Runnable()
{
@Override
public void run()
{
list.setAdapter(friendAdapter);
//list.setOnItemClickListener(EditStaff.this);
}
});
}
catch (Exception e)
{
System.out.println("StaffProgess Exception Caught:"+e.getMessage());
}
return Boolean.TRUE;
}
@Override
protected void onPreExecute()
{
friendsProgress=new ProgressDialog(Friends.this);
friendsProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
friendsProgress.setIndeterminate(true);
friendsProgress.setMessage("Loading...");
friendsProgress.setOwnerActivity(Friends.this);
friendsProgress.show();
}
@Override
protected void onPostExecute(Boolean Result)
{
friendsProgress.dismiss();
friendAdapter.notifyDataSetChanged();
}
}
这里是 getFriendsList 函数实现:
public void getFriendList(){
Request request = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users, Response response) {
// TODO Auto-generated method stub
for(int i=0; i<users.size();i++)
{
GraphUser user = users.get(i);
Friend objFriend = new Friend();
objFriend.setFriendID(user.getId());
objFriend.setFriendName(user.getName());
Drawable dd =Friends.LoadImageFromWebOperations("http://graph.facebook.com/" + objFriend.getFriendID() + "/picture");
objFriend.setFriendPic(dd);
//objFriend.setFriendPic("http://graph.facebook.com/" + objFriend.getFriendID() + "/picture");
friendsList.add(objFriend);
//friendAdapter.notifyDataSetChanged();
Log.d("Friend's Id", objFriend.getFriendID());
Log.d("Friend's Name", objFriend.getFriendName());
//Log.d("Friend's Pic", objFriend.getFriendPic());
Log.d("Friend's List Count", Integer.toString(friendsList.size()));
}
}
});
Request.executeBatchAsync(request);