I have a Button and a TextView. When I hold this Button for 1 second or so, the TextView should increment 1 by 1 in a 0.5 seconds interval.
I’m kind of lost and don’t know what I should use here. Any help is appreciated.
EDIT: I forgot to say that I have an onClick event too. When I make a small click it adds 0.1 (this is already working).
This is what I’ve come out so far.. but no results. The activity just stop working.
btnPlusPastryDosage.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent motion)
{
Handler myHandler = new Handler();
Runnable runnable = new Runnable()
{
public void run()
{
String valueStr = txtPastryDosage.getText().toString();
valueStr = valueStr.replace(',', '.');
BigDecimal value = new BigDecimal(valueStr);
value = value.subtract(new BigDecimal("1"));
if(value.doubleValue() >= 0) txtPastryDosage.setText(String.valueOf(value));
}
};
while(motion.getAction() == MotionEvent.ACTION_DOWN)
{
myHandler.postDelayed(runnable, 500);
}
return false;
}
});
OnClick, make a Handler to post a Runnable that sets the height and width of the button, and increments it. Save the height/width somewhere. Each post method of the handler should check if the button is still pressed. If not, remove all callbacks.
Handler: http://developer.android.com/reference/android/os/Handler.html
Runnable: http://developer.android.com/reference/java/lang/Runnable.html