LoginButton原生片段 [英] LoginButton with native Fragment
问题描述
我想在这里<一个使用教程来实现Facebook LoginButton href="https://developers.facebook.com/docs/android/login-with-facebook/v2.0#step2">https://developers.facebook.com/docs/android/login-with-facebook/v2.0#step2
现在的问题是就行了 authButton.setFragment(本);
。
The problem is on the line authButton.setFragment(this);
.
我使用的是原生片段(android.app.Fragment),但setFragment需要一个支持片段(android.support.v4.app.Fragment)。
I'm using native fragments (android.app.Fragment) but setFragment expects a support Fragment (android.support.v4.app.Fragment).
编辑:我不能切换到支持的片段,我有一个使用原生片段一个大的应用程序
I cannot switch to support Fragments, I have a big app that uses native Fragments.
推荐答案
我认为你正在寻找的解决方案是下面的包装类。使用这个你可以叫
I think the solution you are looking for is the wrapper class below. Using this you can just call
authButton.setFragment(new NativeFragmentWrapper(this));
该包装是一款支持片段,只是通过该方法从Facebook的LoginButton调用原生片段。我用这个和它工作正常。
The wrapper is a support fragment and just passes the method calls from the facebook LoginButton to the native fragment. I'm using this and it works fine.
public class NativeFragmentWrapper extends android.support.v4.app.Fragment {
private final Fragment nativeFragment;
public NativeFragmentWrapper(Fragment nativeFragment) {
this.nativeFragment = nativeFragment;
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
nativeFragment.startActivityForResult(intent, requestCode);
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
nativeFragment.onActivityResult(requestCode, resultCode, data);
}
}
这篇关于LoginButton原生片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!