Reputation: 3
i have checked this links: 1- How to show a button after 5 seconds in android studio?
2- How make a button invisible for 1 or 2 second on another button click
But i couldnt understand where should i this handler in my code. I tried but didnt worked. "While u r going to home heard a scream " after this text i want to make visible my buttons. İ hope i could express myself.
This is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
final TypeWriter tw = (TypeWriter) findViewById(R.id.tv);
tw.setText("");
tw.SetCharacterDelay(120);
tw.animatedText("While u r going to home heard a scream ")
Button btn2 = (Button) findViewById(R.id.button3);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent c = new Intent(Main2Activity.this,Main3Activity.class);
startActivity(c);
}
});
}
}
Upvotes: 0
Views: 289
Reputation: 2847
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Button b = (Button) findViewById(R.id.btn);
invisibleButton(b);
}
private void invisibleButton(final View view){
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
view.setVisibility(View.GONE);
}
}, 1000 * 3);
}
}
But Remember your import
Handler
should be-:
import android.os.Handler;
EDIT
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Button b = (Button) findViewById(R.id.button5);
b.setVisibility(View.GONE);
visibleButton(b);
}
private void visibleButton(final View view){
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
view.setVisibility(View.VISIBLE);
}
}, 1000 * 3);
}
}
Upvotes: 0
Reputation: 8237
Try this .
Button btn2 = (Button) findViewById(R.id.button3);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 3 secs
}
}, 3000);
Upvotes: 1