Following is the code from Fabric Docs. How can I assign setCallback()
into ImageView
because I need to do authentication after ImageView
is clicked (not TwitterButton
):
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterLoginButton;
...
loginButton = (TwitterLoginButton) findViewById(R.id.login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
});
and after that how can I pass the result to the ImageView back?
Again, code from mentioned website:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Pass the activity result to the login button.
loginButton.onActivityResult(requestCode, resultCode, data);
}
Any idea?
You dont need to write additional classes for that purpose. You can do twitter login with any custom layout. I have already answered a question which is similar to yours.
Please refer this link.
This is my solution.
You need to write
TwitterLoginImageView.class
:Next add
TwitterLoginImageView
as yourImageView
to the layout file. E.g.:After that you need to initialize this
TwitterLoginImageView
in yourActivity
/Fragment
file:using
ButterKnife
:using standard method:
and in
onCreate()
method:Finally, you need to continue with this site: Authentication - Log in with Twitter | Fabric.io.
That helps me!