I have a Button
that whenever the user clicks it, it increases the number in my EditText
, but i want to have an onTouch method that when the user keeps their finger on the button the number increases with more speed(continuously), something like the backspace, that when you click it, it deleted just one letter and when you keep it down, it deletes the words faster, so i have both ontouch and onclick in my code, but whenever i click the button only onTouch triggers, what should i do? can anybody help, please? I have searched a lot but couldn't find anything that helps me
Here is part of my code
btnFineUp.setOnTouchListener (this);
btnFineUp.setOnClickListener (this);
@override
public void onClick (View view)
{
switch (view.getId ())
{
case R.id.btn_fine_up:
{
View v = findViewById (getCurrentFocus ().getId ());
EditText editText;
if (v instanceof EditText)
{
editText = (EditText) v;
}
else
{
return;
}
int calcStateAmp = +1;
if (view.getId () == R.id.btn_fine_up)
{
calcState_2 = upAndDown.getFineUpAmp () * calcStateAmp;
calcStateAmp = calcState_2;
}
double currentValue;
if (StringUtils.isNullOrEmpty (editText.getText ().toString ()))
{
currentValue = 0;
}
else
{
currentValue = Double.parseDouble (editText.getText ().toString ());
}
switch (getCurrentFocus ().getId ())
{
case R.id.txt_va1_a:
case R.id.txt_va2_a:
case R.id.txt_va3_a:
case R.id.txt_vb1_a:
editText.setText (String.format (Locale.ENGLISH, "%.2f", currentValue + (0.01 * calcStateAmp)));
break;
}
@Override
public boolean onTouch (View view, MotionEvent motionEvent)
{
switch (view.getId ())
{
case ir.vebko.R.id.btn_fine_up:
{
View v = findViewById (getCurrentFocus ().getId ());
EditText editText;
if (v instanceof EditText)
{
editText = (EditText) v;
}
else
{
return false;
}
int calcStateAmp = +1;
if (view.getId () == R.id.btn_fine_up)
{
calcStateAmp = calcState_2;
}
double currentValue;
if (StringUtils.isNullOrEmpty (editText.getText ().toString ()))
{
currentValue = 0;
}
else
{
currentValue = Double.parseDouble (editText.getText ().toString ());
}
switch (getCurrentFocus ().getId ())
{
case ir.vebko.R.id.txt_va1_a:
case ir.vebko.R.id.txt_va2_a:
case ir.vebko.R.id.txt_va3_a:
case ir.vebko.R.id.txt_vb1_a:
editText.setText (String.format (Locale.ENGLISH, "%.2f", currentValue + (0.01 * calcStateAmp)));
break;
}
return true;
}