When I click on a button, another button should be clicked programmatically after 2 seconds.
Helper.setTimeout(() -> {
_view.findViewById(R.id.turbineStandBy).performClick();
}, 2000);
When I run this code, I get this exception:
Only the original thread that created a view hierarchy can touch its views.
public static void setTimeout(Runnable runnable, int delay){
new Thread(() -> {
try {
Thread.sleep(delay);
runnable.run();
}
catch (Exception e){
System.err.println(e);
}
}).start();
}
I think that I have to override the method run()
but how can I do that in my setTimeout() method?