Facebook FriendPickerFragment没有显示任何朋友

时间:2014-01-01 00:16:28

标签: android facebook-android-sdk

知道为什么列表可能为空?

代码如下。

public class PickFBFriendsActivity extends FragmentActivity {
FriendPickerFragment friendPickerFragment;

// A helper to simplify life for callers who want to populate a Bundle with the necessary
// parameters. A more sophisticated Activity might define its own set of parameters; our needs
// are simple, so we just populate what we want to pass to the FriendPickerFragment.
public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) {
    intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId);
    intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect);
    intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        friendPickerFragment.setUserId(null);
        fm.beginTransaction()
                .add(R.id.friend_picker_fragment, friendPickerFragment)
                .commit();
    } else {
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFBFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {

            setResult(RESULT_OK, null);
            finish();
        }
    });
}

private void onError(Exception error) {
    String text = getString(R.string.exception, error.getMessage());
    Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
    toast.show();
}


@Override
protected void onStart() {
    super.onStart();

}

}

请注意,它与样本1几乎相同。

1 个答案:

答案 0 :(得分:3)

想出来:我的onStart()方法不完整,缺少以下一行:

        friendPickerFragment.loadData(false);

必须意外删除它。