Reputation: 516
How can I simulate onLongClick
? Basically I need the user to click once - and a method to turn it into longClick
without actually long clicking.
Upvotes: 0
Views: 163
Reputation: 5635
View dummyView = findViewById(R.id.dummy_view);
dummyView .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dummyView .performLongClick();
}
});
Upvotes: 1
Reputation: 235
On Android, every View object has the method performLongClick, that allows you to simulate the action programmatically. But you have to set the listener before:
View dummyView = findViewById(R.id.dummy_view);
dummyView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
And now you can call dummyView.performLongClick()
, to simulate the longClick action
Upvotes: 2