Reputation: 65
I am making an app with a webview. This webview uses some time by loading the url so I want a Imageview to be shown for about 3 seconds before it disappears. This is my layout file. How can i swap the visibility on these two views after 3 seconds have gone after app launch?
<ImageView android:id="@+id/imageLoading1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="visible"
android:src="@drawable/logo"
/>
<android.webkit.WebView
android:id="@+id/wvwMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
>
Upvotes: 2
Views: 2042
Reputation: 4981
Try this JavaScript:
myImageView.postDelayed(
new Runnable(){
public void run(){
myImageView.setVisibility(View.GONE);
}
},3000);
Upvotes: 0
Reputation: 1942
This code is a Sample that how you can works with a CountDown.
import android.os.CountDownTimer;
public class Sample extends Activity {
MyCustomCountDown timer;
ImageView imageview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageview = (ImageView) findViewById(R.id.imageLoading1);
timer = new MyCustomCountDown(3 * 1000, 1000);
timer.start();
}
public class MyCustomCountDown extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
//some script here
imageview.setVisible(View.GONE); ////HERE HIDE YOUR IMAGE.
}
@Override
public void onTick(long millisUntilFinished) {
//some script here
}
}
}
Here is a Sample to how make a Splash
Upvotes: 0
Reputation: 2114
imageView.postDelayed(new Runnable(){
public void run(){ imageView.setVisibility(View.GONE);}
},3000);
Upvotes: 1
Reputation: 2606
new Handler().postDelayed(new Runnable() {
public void run() {
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
findViewById(R.id.wvwMain).setVisibility(View.VISIBLE);
}
}, 3000);
This will wait 3 seconds in the background, and after that it changes back to the UI thread and sets the visibilities.
Upvotes: 5