Class Button

All Implemented Interfaces:
Drawable.Callback, ViewTreeObserver.OnPreDrawListener
Direct Known Subclasses:
CompoundButton

public class Button extends TextView
A user interface element the user can tap or click to perform an action.

To specify an action when the button is pressed, set a click listener on the button object in the corresponding fragment code:


 public class MyFragment extends Fragment {
     @Nullable
     @Override
     public View onCreateView(@Nullable ViewGroup container, ...) {
         final Button button = new Button;
         button.setOnClickListener(v -> {
              // Code here executes on UI thread after user presses button
         });
         // ...
         return button;
     }
 }
 

The above snippet creates an instance of View.OnClickListener and wires the listener to the button using View.setOnClickListener(icyllis.modernui.view.View.OnClickListener). As a result, the system executes the code you write in lambda expression after the user presses the button.

The system executes the code in onClick on the UI thread. This means your onClick code must execute quickly to avoid delaying your app's response to further user actions.

  • Constructor Details

    • Button

      public Button(Context context)
  • Method Details

    • onResolvePointerIcon

      public PointerIcon onResolvePointerIcon(@Nonnull MotionEvent event)
      Description copied from class: View
      Returns the pointer icon for the motion event, or null if it doesn't specify the icon. The default implementation does not care the location or event types, but some subclasses may use it (such as WebViews).
      Overrides:
      onResolvePointerIcon in class TextView
      Parameters:
      event - The MotionEvent from a mouse
      See Also: