我想要做的是,当活动打开时,内容将开始在列表视图中加载/显示"自动"。我使用简单的facebook库来获取朋友列表,现在我有一个按钮将内容提取到列表视图,但我想让它自动加载。
以下是活动:
@Override
public void onResume() {
super.onResume();
mSimpleFacebook = SimpleFacebook.getInstance(this);
}
final OnFriendsListener mOnFriendsListener = new OnFriendsListener() {
@Override
public void onFail(String reason) {
hideDialog();
toast("You are not logged in");
Log.w(TAG, reason);
}
@Override
public void onException(Throwable throwable) {
hideDialog();
toast("Error");
Log.e(TAG, "Bad thing happened", throwable);
}
@Override
public void onComplete(List<Profile> friends) {
// populate list
List<String> values = new ArrayList<String>();
for (Profile profile : friends) {
//profile.getInstalled();
values.add(profile.getName());
}
ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
mFriendsList.setAdapter(friendsListAdapter);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
以下是加载内容的按钮:
mButtonGetFriends = (Button) findViewById(R.id.button_get_friends);
mButtonGetFriends.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSimpleFacebook.getFriends(mOnFriendsListener);
}
});
如何在打开活动时自动加载内容,而无需单击按钮?