I need to launch add event when user keep during 2 seconds on listview. After that vibrate device and show dialog asking "Add to favorite?".
I've trying whit this.
lv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.AXIS_PRESSURE){
long eventDuration =
android.os.SystemClock.elapsedRealtime()
- event.getDownTime();
//Put up the Yes/No message box
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
alert
.setTitle("Service")
.setMessage("Add to favorite?")
//.setIcon(R.drawable.chile1)
.setPositiveButton("Si", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Activity.class);
startActivity(intent);
}
})
.setNegativeButton("No", null) //Do nothing on no
.show();
}
return false;
}
the code above show 5 time the dialog.