extends Button : Button « UI « Android






extends Button

 
//package com.bitle.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
interface OnButtonActionListener {
  public void onButtonDown(View view);
  public void onButtonUp(View view);
}

public class MyButton extends Button {

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

  public MyButton(Context context, AttributeSet attrs) {
    super(context, attrs);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    
    case MotionEvent.ACTION_DOWN:
      buttonListener.onButtonDown((View)this);
      break;
    case MotionEvent.ACTION_UP:
      buttonListener.onButtonUp((View)this);
      break;
    }
    return super.onTouchEvent(event);
  }
  
  public void setOnButtonActionListener(OnButtonActionListener listener) {
    buttonListener = listener;
  }
  
  protected OnButtonActionListener buttonListener;
}

   
  








Related examples in the same category

1.Add Button to Activity
2.Add Button from layout xml file
3.Add button on click listener
4.Button on click event
5.Get data from RadioButton
6.Set one of the three radio buttons to be selected by default, using android:checked = "true".
7.Load Button from layout xml file and add action listener
8.Add listener to Toggle Button
9.Layout Radio buttons with RadioGroup
10.Layout Button inside Activity
11.Using switch statement to check the RadioButton selection
12.ImageButton Demo
13.Set Button text in xml file
14.Is ToggleButton selected
15.Set Button width and height
16.Show or hide button
17.Using ImageButton
18.Clear RadioButton selection
19.Add key listener to add the new todo item when the middle D-pad button is pressed.
20.Set ToggleButton on/off text
21.Using Button to control MediaPlayer
22.Button Gallery
23.A gallery of basic controls: Button, EditText, RadioButton, Checkbox, Spinner. This example uses the light theme.
24.A list view that demonstrates the use of setEmptyView. This example alos uses a custom layout file that adds some extra buttons to the screen.
25.This demonstrates the use of the PopupMenu class. Clicking the button will inflate and show a popup menu from an XML resource.
26.Adding a radio button programmatically
27.Create Button
28.Create Image Button