Note that there are some explanatory texts on larger screens.

plurals
  1. POChange a value smoothly increasing in speed by holding down a button
    primarykey
    data
    text
    <p>I have been steaming over this one a few days now. I try to have a selector for a big range of numbers... within int-limits. You ought to hold down a button and the value should change slow and the longer you press the more rapid it changes. You all know that kind of button, don't you?! :D It has to be precise, yet fast to enter the number. I use a <code>OnTouchListener</code>. The event allows to <code>.getDownTime()</code>. </p> <p>I tried a lot, but always only got it to skip numbers (not really but too fast to use) or not repeatingly increase the value while holding down the button. If run without changes it is pretty fast, but it would be nice, if it starts to make 10 100 or 1000-jumps if it is held down long enough. </p> <p>I prepared a little SSCCE looking like this:</p> <p><img src="https://i.stack.imgur.com/uQy2E.png" alt="Screenshot of SSCCE"></p> <pre><code>public class ValueChangerSSCCE extends Activity implements OnTouchListener { Button plusButton; TextView valueView; Button minusButton; int value; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); plusButton = new Button(this); plusButton.setText("+"); plusButton.setTextSize(120f); plusButton.setOnTouchListener(this); layout.addView(plusButton); valueView = new TextView(this); valueView.setGravity(Gravity.CENTER_HORIZONTAL); valueView.setTextColor(Color.WHITE); valueView.setText(value + ""); valueView.setTextSize(120f); layout.addView(valueView); minusButton = new Button(this); minusButton.setText("-"); minusButton.setTextSize(120f); minusButton.setOnTouchListener(this); layout.addView(minusButton); setContentView(layout); } /* * Called when a button is pressed */ @Override public boolean onTouch(View v, MotionEvent event) { if (v == plusButton) { value++; } else if (v == minusButton) { value--; } valueView.setText(value + ""); return false; } } </code></pre> <p>For devices with low resolution one might have to decrease the text-sizes. </p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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