Michael Joseph Aubry
Michael Joseph Aubry

Reputation: 13452

Fab button android onClick is crashing the app?

The (Floating action button) works but when I try to set it as a button it crashes the app?

Button MyButton = (Button) findViewById(R.id.fab);
MyButton.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
    // Perform action on click
  }
});

The above crashes the app, but when I remove it everything is fine? Any ideas?

https://github.com/makovkastar/FloatingActionButton

Upvotes: 0

Views: 825

Answers (1)

cliff.meyers
cliff.meyers

Reputation: 17734

The FloatingActionButton from this library extends ImageView which extends View:

https://github.com/makovkastar/FloatingActionButton/blob/master/library/src/main/java/com/melnykov/fab/FloatingActionButton.java

It is not a subclass of the Android Button. Cast instead to FloatingActionButton:

FloatingActionButton myButton = (FloatingActionButton) findViewById(R.id.fab);

Upvotes: 4

Related Questions