Code example for Button

Methods: setTextsetTextSizesetTypeface, setOnClickListener, setOnLongClickListener, setOnTouchListener

0
  private Typeface getButtonTypeface() {
    return Typeface.MONOSPACE;
  } 
 
  private void initIncrementButton( Context context){
    increment = new Button( context );
    increment.setTextSize( mTextSize );
    increment.setText( " + " );
    increment.setTypeface(getButtonTypeface());
 
    // Increment once for a click 
    increment.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
              increment(); 
            } 
        }); 
 
    // Auto increment for a long click 
    increment.setOnLongClickListener(
        new View.OnLongClickListener(){
          public boolean onLongClick(View arg0) {
            autoIncrement = true;
            repeatUpdateHandler.post( new RepetetiveUpdater() );
            return false; 
          } 
        } 
    ); 
 
    // When the button is released, if we're auto incrementing, stop 
    increment.setOnTouchListener( new View.OnTouchListener() {
      public boolean onTouch(View v, MotionEvent event) {
        if( event.getAction() == MotionEvent.ACTION_UP && autoIncrement ){
          autoIncrement = false;
        } 
        return false;