Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For that to work, you need a thread that will update the integer value when you long press on a button.</p> <p>Create a handler in your activity:</p> <pre><code>private Handler repeatUpdateHandler = new Handler(); </code></pre> <p>And 2 vars which will state: is it increment or decrement? Only one set at a time.</p> <pre><code>private boolean mAutoIncrement = false; private boolean mAutoDecrement = false; </code></pre> <p>And the present number value</p> <pre><code>public int mValue; </code></pre> <p>And a class that will run in another thread:</p> <pre><code>class RptUpdater implements Runnable { public void run() { if( mAutoIncrement ){ increment(); repeatUpdateHandler.postDelayed( new RptUpdater(), REP_DELAY ); } else if( mAutoDecrement ){ decrement(); repeatUpdateHandler.postDelayed( new RptUpdater(), REP_DELAY ); } } } </code></pre> <p>Add a long press listener to your button:</p> <pre><code>mBTIncrement.setOnLongClickListener( new View.OnLongClickListener(){ public boolean onLongClick(View arg0) { mAutoIncrement = true; repeatUpdateHandler.post( new RptUpdater() ); return false; } } ); mBTIncrement.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if( (event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL) &amp;&amp; mAutoIncrement ){ mAutoIncrement = false; } return false; } }); </code></pre> <p>In the above case the button is the increment one. Create another button which will set mAutoDecrement to true.</p> <p>And decrement() will be a function, which will set your instance int variable like this:</p> <pre><code>public void decrement(){ mValue--; _value.setText( ""+mValue ); } </code></pre> <p>You figure the increment out. Oh and REP_DELAY is a static int variable set to 50.</p> <p>I see this is an excerpt from Jeffrey Cole's open source NumberPicker available at <a href="http://www.technologichron.net/" rel="noreferrer">http://www.technologichron.net/</a> Proper author's attribution must be added.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload