java


Image Button appear after some seconds [duplicate]


This question already has an answer here:
How to pause / sleep thread or process in Android?
8 answers
I want to make an ImageButton disappear after being clicked, and after two seconds the ImageButton appear again.
I've searched on the stackoverflow but I cannot find any answer.
I tried to use Timer, but my activity start to crash.
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View button) {
button.setBackgroundResource(R.drawable.avatar_dead);
final long changeTime = 1000L;
button.postDelayed(new Runnable() {
#Override
public void run() {
button.setBackgroundResource(R.drawable.avatar_small);
}
}, changeTime);
}
});
You can use postDelayed method, the first argument is a Runnable and the second are milliseconds to wait before execute it :
new Handler().postDelayed(()->myButton.setVisibility(View.VISIBLE),2000);

Related Links

How to get a random item from a list with some preference [duplicate]
Broadcast Receiver is called everytime
how to search NA value in String array using java [duplicate]
Getting stackoverflow when cutting certain strings into slices
Execute Maven Plugin in every Build
Speed up mongo queries by parallel them and use a ThreadPool?
Issues using android studio to get time of travel between two points
Kotlin delegating to a future
Calculation error in Java
What problems occur when creating static object fields?
I have “broken pipe” exception using Sockets and Netty. What's wrong?
How to create a single thread cooldown
Receive UTF-8 response from Http Post
How to get the supported image formats that the method ImageIO.write can export?
An elegant way to join arrays of arrays of strings by two different separators in java by stream
how to mock private static method in java with PowerMockito which invoked by static Initializer?

Categories

HOME
oracle11g
iot
read-eval-print-loop
maven-3
cakephp-2.5
fingerprint
ojdbc
mouse
adfs
ssl-client-authentication
node-pdfkit
apache-cayenne
usergrid
moonmail
remote-access
zebra-printers
vaadin7
angular-ui
pythonanywhere
jtextfield
grails3
ml
intentfilter
zurb-foundation-6
blazemeter
trading
emgucv
angular2-aot
microsoft-sync-framework
compatibility
large-file-upload
webkitspeechrecognition
gsmcomm
nouislider
calibre
bower-install
bytecode-manipulation
android-ble
adobe-premiere
impersonation
quadratic-programming
botbuilder
gpx
scrollable
network-flow
react-scripts
pnotify
kbuild
feeds
lift-json
flutterwave
dynamics-sl
time-and-attendance
spring-android
trash
ctest
impresspages
lttng
blackberry-10
associative-array
ios8-today-widget
qdialog
sailfish-os
fluid-dynamics
pretty-print
notify
lustre
operator-precedence
gadt
mdt
balanced-payments
industrial
gridfs
ril
html4
http-unit
referrer
path-separator
ohm
nsdatecomponents
nsobject
zpt
winbugs14
disclosure
sql-server-profiler
telerik-scheduler
lpeg
yslow
sudzc
createwindow
gin
rescale
brewmp
photoshop-cs4
privilege

Resources

Encrypt Message