I have one button , click that button will show info , but I don't want to click it by myself , I hope it can be automatically running in first time. maybe 0.1 seconds after ? it's possible ? Thanks.
Edit : Thanks All. I have already solution.
I have one button , click that button will show info , but I don't want to click it by myself , I hope it can be automatically running in first time. maybe 0.1 seconds after ? it's possible ? Thanks.
Edit : Thanks All. I have already solution.
You can use a Handler and a delayed Runnable
to be executed on the UI thread after 1 seconds
to perform automatically of button use performClick();
public boolean performClick ()
Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound
using below code you can automatically Click a Button after one second
add this sample code in your onCreate()
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
btnOk.performClick();
}
}, 1000);
You need to call button's perfomClick() method and set button onClickListener on your activity for button and set following code on your activity's onCreate method.
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.your_layout); Button btnYourButton = (ImageView) findViewById(R.id.btnYourButton);
//TODO Number Of Second You Want Delay.
int noOfSecond = 1;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//TODO Set your button auto perform click.
btnYourButton.performClick();
}
}, noOfSecond * 1000);
}