Android:在活动负载上加载内容

时间:2014-04-10 16:35:04

标签: android facebook

我有这段代码从facebook加载朋友列表:

@Override
public void onResume() {
    super.onResume();
    mSimpleFacebook = SimpleFacebook.getInstance(this);
}

    final OnFriendsListener mOnFriendsListener = new OnFriendsListener() {

        @Override
        public void onFail(String reason) {
            hideDialog();
            // insure that you are logged in before getting the friends
            Log.w(TAG, reason);
        }

        @Override
        public void onException(Throwable throwable) {
            hideDialog();
            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) {
                values.add(profile.getName());
            }
            ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, 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);
    } 

我有一个按钮可以在点击时加载好友列表,但我想在活动打开时无需启动好友列表而无需点击按钮,我怎么能修改代码呢?

1 个答案:

答案 0 :(得分:0)

你可以在onCreate()方法中找到facebook加载代码,例如
或者您可以使用Loader并在此方法中找到代码