onResume equivalent in custom Preference class?

104 views Asked by At

I have a custom Preference class that display's a PlusOne button. According to Google docs, I need to initialize this button in the onResume function of an Activity class. What would be the equivalent in a Preference class? What function can I use to refresh the view everytime its reloaded? I've searched Google for an answer but with no luck.

1

There are 1 answers

0
Steve C. On

So I figured out how to get the Google+ PlusOneButton to work and sync the amount of plus ones.

In your Settings activity onCreate set your custom layout for the settings

    setContentView(R.layout.custom_layout);

Your custom layout should look like this:

    <LinearLayout 
        android:orientation="vertical" 
        android:background="@drawable/backgroundone" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
 >




<ListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="0.0dip" 
    android:cacheColorHint="#00000000" 
    android:layout_weight="1.0" />



<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:layout_marginBottom="25dp" >



    <com.google.android.gms.plus.PlusOneButton
        android:id="@+id/plus_one_medium_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="10sp"
        plus:size="medium" >
    </com.google.android.gms.plus.PlusOneButton>
</RelativeLayout>

In your Settings Activity onCreate method add the following:

    mPlusOneMediumButton = (PlusOneButton) findViewById(R.id.plus_one_medium_button);

Now add the onResume method to your Settings activity:

  @Override
  protected void onResume()
  {
    super.onResume();
    mPlusOneMediumButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
  }

URL is the url of your app on Google Play

Request code should be 0 according to developer docs.