Search code examples
androidfacebookfacebook-android-sdk

Facebook SDK 3 Login Button Identify on click


I am using com.facebook.widget.LoginButton component to log into Facebook:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.splash, container, false);
    LoginButton authButton = (LoginButton) view.findViewById(R.id.login_button);
    stat = (TextView) view.findViewById(R.id.profile_name);
    //authButton.setFragment(this);
    authButton.setReadPermissions(Arrays.asList("user_likes", "user_status",
            "user_status", "user_events", "friends_events"));

    return view;
}

I want to prompt the user his login status, so I need to change a text view when Facebook's button was pressed.

But I can't seem to find a way to identify user's click, without changing Facebook's lib, or override LoginButton native listener.


Solution

  • I've run into the same problem while trying to implement a login lib for my application. So far the solution I found, still not sure whether it is the best or not, was changing LoginClickListener Class inside facebook-sdk from private to public, so I could override the onClick method on my Activity. Here is the line I've changed.

    From:

    private class LoginClickListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            ...
    

    To:

    public class LoginClickListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            ...
    

    Then on my Activity I'm able to Override onClick method.

    LoginButton facebookButton = (LoginButton) findViewById(R.id.authButton);
    facebookButton.setOnClickListener( facebookButton.new LoginClickListener(){
        @Override
        public void onClick(View v) {
            //Do whatever u want
            super.onClick(v);
        }
    });
    

    Good luck.