Advertisement
Javinator9889

DonationsActivity - Solution

Mar 8th, 2018
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. public class DonationsActivity extends FragmentActivity {
  2.     private DonationsFragment donationsFragment = null;
  3. . . .
  4. // (INSTANTITATE THE DONATIONS FRAGMENT AS IN THE EXAMPLE)
  5.     @Override
  6.     public void onCreate(Bundle savedInstanceState) {
  7. . . .
  8.             this.donationsFragment = DonationsFragment.newInstance(. . .);
  9. . . .
  10.     }
  11. // How I solved it
  12.     @Override
  13.     protected void onPostCreate(@Nullable Bundle savedInstanceState) {
  14.         super.onPostCreate(savedInstanceState);
  15.         try {
  16.             Button googleDonationsButton = donationsFragment.getActivity()
  17.                     .findViewById(R.id.donations__google_android_market_donate_button);
  18.             googleDonationsButton.setOnClickListener(new View.OnClickListener() {
  19.                 @Override
  20.                 public void onClick(View v) {
  21.                     try {
  22.                         donationsFragment.donateGoogleOnClick(v);
  23.                     } catch (IllegalStateException e) {
  24.                         new MaterialDialog.Builder(DonationsActivity.this)
  25.                                 .title(R.string.donations__google_android_market_not_supported_title)
  26.                                 .content(R.string.donations__google_android_market_not_supported)
  27.                                 .cancelable(true)
  28.                                 .positiveText(R.string.accept)
  29.                                 .build().show();
  30.                     }
  31.                 }
  32.             });
  33.         } catch (NullPointerException e) {
  34.             Log.e("DonationsActivity", "Unable to get button-fragment. Full trace: "
  35.             + e.getMessage());
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement