How can I integrate Facebook LoginButton into PreferenceScreen

I want my users to be able to connect / disconnect from Facebook via the settings screen, which uses a simple PreferenceScreen

How can I integrate this custom Button class in PreferenceScreen . https://developers.facebook.com/docs/reference/android/current/LoginButton/

The login button greatly simplifies session management, which otherwise would have to be done manually if I provide a simple Preference and use onClickListener

+6
source share
3 answers

Use the normal preference screen with text that tells the user to click to enter facebook. Register the OnPreferenceClickListener when it is clicked, and in the listener definition use this code:

 LoginButton l = new LoginButton(this); l.performClick(); 

What I'm basically trying to do is programmatically create a button that never displays, and then call its onClick function, which launches the Facebook login / logout procedure. Does it do the trick?

+2
source

What I would like to do is create a custom XML that will contain your preferences using the login button built in with LinearLayout. Using LinearLayout is important because the way you handle onClick events is that the lowest child with onClickListener takes precedence over the parent onClickListener. This means that the only time you call the login onClick logic is when the user directly clicks the button.

In the code, you can now extend the PreferenceFragment class, where you can configure onClick listeners and all that you may need. Please note that if you support API level 10 or lower, you may need to use it to create user preferences:

 addPreferencesFromResource(R.xml.custom_preference); 

Hope this is what you are looking for and I appreciate any feedback.

+2
source

Extend the preference class and override onCreateView (parent ViewGroup) . You can then return your LoginButton as your preference. But make sure that you implement all the necessary methods for the preferences to work correctly. It details how to create custom settings.

+1
source

Source: https://habr.com/ru/post/956240/


All Articles