我想要做的是,当活动打开时,内容将开始“自动”在列表视图中加载/提取。我正在使用简单的 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);
}
});
打开活动时,如何在不单击按钮的情况下自动加载内容?