Question

UPDATE: I found out that this is my issue https://code.google.com/p/google-plus-platform/issues/detail?id=704

A while ago I implemented the +1 button in my app as a preference. It worked well until a few weeks and now the button is always gray. If I touch it I get the 'loading' circle and it never stops rotating.

I've debugged my app and made sure that initialize is called.

Is anyone else experiencing problem with it?

Thanks.

My preference code:

public class PlusOnePreference extends Preference { 

public PlusOnePreference(Context context) {
    super(context);     
}

public PlusOnePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public PlusOnePreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onBindView(View view) {
    super.onBindView(view);
    PlusOneButton plusOneButton = (PlusOneButton)view.findViewById(R.id.plus_one_button);
    plusOneButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
}

My preference layout:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.plus.PlusOneButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
android:descendantFocusability="blocksDescendants"
plus:size="standard" 
plus:annotation="inline"/>
Était-ce utile?

La solution 2

This seems to be fixed with Google Play Services 4.1 .

Autres conseils

So I was having problems with this because the Google plus one icon would stay grey like you stated until the preference view was reloaded (i.e. navigating else where and then coming back, having the preference scroll out of the screen and then back, etc). The problem is because you need to make a call to mPlusOneButton.initialize() in the onResume() function of the activity that has the Plus One Button. So basically, I just made a public method in the preference that makes the initialize call and then called it in the onResume() function.

The Activity:

Preference preference; 
@Override
public void onResume()
{
    super.onResume();
    if(preference!= null)
    {
        preference.reloadGooglePlusOneButton();
    }

}

In the preference:

public void reloadGooglePlusOneButton()
{
    if(mPlusOneButton != null)
    {
        mPlusOneButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top