I am trying to set up a login with facebook in my application. I have one main activity and several fragments. Using facebook sdk 3.5.2, I did an endless rendering tutorial , but when I add this line authButton.setFragment(this); She gives me the error that my fragment is not a fragment.
(The setFragment method (Fragment) in the LoginButton type is not applicable for arguments (FaceobookLoginFragment))
I add fragments from the main class to the action bar, for example,
ActionBar bar = getActionBar(); bar.setDisplayShowHomeEnabled(false); bar.setDisplayShowTitleEnabled(false); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); String FloginTitle = "Flogin"; ActionBar.Tab FloginTab = bar.newTab(); FloginTab.setText(FloginTitle); FloginTab.setTabListener(new TabListener(this, FloginTitle, FaceobookLoginFragment.class)); bar.addTab(FloginTab);
And this is a listener
public class TabListener implements ActionBar.TabListener{ private final FragmentActivity fActivity; private final String ftag; private final Class fragmentClass; private Fragment fragment; public TabListener(FragmentActivity activity, String tag, Class fragmentClass ) { this.fActivity = activity; this.ftag = tag; this.fragmentClass = fragmentClass; this.fragment = activity.getFragmentManager().findFragmentByTag(tag); } @Override public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {
And Facebook Fragment
public class FaceobookLoginFragment extends Fragment { private static final String TAG = "FBLOGINFRAGMENT"; private UiLifecycleHelper uiHelper; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(getActivity(), callback); uiHelper.onCreate(savedInstanceState); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.facebook_login_layout, container, false); LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton); authButton.setFragment(new FaceobookLoginFragment()); return view; } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { Log.i(TAG , "Logged in..."); } else if (state.isClosed()) { Log.i(TAG, "Logged out..."); } } private Session.StatusCallback callback = new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; @Override public void onResume() { super.onResume(); uiHelper.onResume(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data); } @Override public void onPause() { super.onPause(); uiHelper.onPause(); } @Override public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); }
UPDATE : found out why .. facebook sdk only works with android support library, so the solution should use android.support.v4.app import. * throughout my application and review everything that includes a support library ...