In my app I need to use one click and long press on a button
on click for some thing(calling Itemclick()) and long press for record sound
and use this code:
send.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
{
recording =false;
t=new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(count>=2)
t.cancel();
count++;
}
});
}
}, 1, 1000);
break;
}
case MotionEvent.ACTION_MOVE:
{
if(count >=2&&!recording)
{
recording=true;
count=0;
Rec=new Recorder();
Rec.startRecord();
}
break;
}
case MotionEvent.ACTION_UP:
{
t.cancel();
if(!recording)
{
count=0;
Itemclick();
break;
}
recording=false;
Rec.StopRecord();
db.open();
db.insert_offline(Rec.getName(), true, false);
listItems.add(Rec.getName());
type.add("v");
adapter.notifyDataSetChanged();
db.close();
Rec=null;
break;
}
}
return false;
}
});
In this code I use a timer for finding long press but I want an easily and faster way to do this.
Do you have any idea or better solution ?