-1

i want create a key pressed (hold key) func for my application.
for example when I press (hold) a button next year the values of textview grow and when I pickup my finger from button, stop working.

anyone can help me i most use which of Listener or function for create it? this is my setOnClickListener but i want button press(hold) work

nextDay.setOnClickListener(new OnClickListener() {
   public void onClick(View v) {
         if (values >= downrange && values <= uprange)
                values++;
         if (values > uprange)
                values = downrange;
         if(values <10)
                  textDayo.setText(PersianReshape.reshape("0"+String.valueOf(values)));
         else
                textDayo.setText(PersianReshape.reshape(String.valueOf(values)));

                }
            });

thanks for your help and sorry for bad english

keyser
  • 18,829
  • 16
  • 59
  • 101
Mostafa Rostami
  • 1,906
  • 20
  • 29

2 Answers2

0

when I press (hold) a button next year the values of textview grow

Have you looked at the DatePicker? This allows you to set a date very easily: datepicker image

You can follow this tutorial


If you do not want to use a DatePickker, you can try to use an OnTouchListener and a Handler to do this yourself, but this is hard to do.

Sam
  • 86,580
  • 20
  • 181
  • 179
0

I understand that you are trying to hold a button (widget) and while holding it to increase the year.

If this is the case then this link should help you. The idea is that you use a timer to update the ui. Something similar is also described here. If your problem is just setting the date though, a simpler way could be the one suggested by Sam above.

Community
  • 1
  • 1
Lefteris
  • 873
  • 2
  • 8
  • 29