进度条终止并进入新屏幕

发布于 2024-12-10 14:13:23 字数 1056 浏览 0 评论 0原文

package com.example.progress;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;

public class ProgressActivity extends Activity  {
ProgressDialog myProgressDialog = null;

    @Override
    public void onCreate(Bundle icicle){
        super.onCreate(icicle);
        myProgressDialog = ProgressDialog.show(ProgressActivity.this,
                "Please wait...", "few seconds.....", true);

new Thread() {
        public void run() {
                try{
                        // Do some Fake-Work
                        sleep(5000);
                } catch (Exception e) { }
                myProgressDialog.dismiss();



        }
}.start();
}
};

这是我的代码...我现在想要的是当进度条完成时,我想进入下一个屏幕...

即使我知道如何使用按钮进入其他屏幕..我无法实现它....

我尝试了这个...

Intent i = new Intent(SplashActivity.this, screen2.class); 开始活动(一);

添加这行代码并替换为 Progress.dismiss();

但它没有成功...请给我看源代码或任何帮助...我只想进入其他屏幕...

我对此很陌生...并且想学习它...任何帮助将不胜感激...

package com.example.progress;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;

public class ProgressActivity extends Activity  {
ProgressDialog myProgressDialog = null;

    @Override
    public void onCreate(Bundle icicle){
        super.onCreate(icicle);
        myProgressDialog = ProgressDialog.show(ProgressActivity.this,
                "Please wait...", "few seconds.....", true);

new Thread() {
        public void run() {
                try{
                        // Do some Fake-Work
                        sleep(5000);
                } catch (Exception e) { }
                myProgressDialog.dismiss();



        }
}.start();
}
};

This is my code... What I want now is when progress bar finishes, i want to go into next screen....

Even tho I know how to go into other screen with using buttons.. I am not able to implement it....

I tried this...

Intent i = new Intent(SplashActivity.this, screen2.class);
startActivity(i);

Add this line of code and replace with the progress.dismiss();

But it didn't work out... Please just show me a source code or any help... I just want to get to other screen...

I am new to this... and want to learn it... Any help would be appreciated...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-12-17 14:13:24

使用 Handler 非常简单...

private Handler handler=new Handler(){

    @Override
public void handleMessage(Message msg) 
{
Intent i = new Intent(SplashActivity.this, screen2.class); 
startActivity(i);
myProgressDialog.dismiss();
}
}

并且在 Oncreate 方法中,您需要随时向处理程序发送消息;

handler.sendEmptyMessageDelayed(0, 5000);//after 5000 millisec msg will be send

Use Handler it is very easy...

private Handler handler=new Handler(){

    @Override
public void handleMessage(Message msg) 
{
Intent i = new Intent(SplashActivity.this, screen2.class); 
startActivity(i);
myProgressDialog.dismiss();
}
}

and In Oncreate method you need to send message to handler whenever you want;

handler.sendEmptyMessageDelayed(0, 5000);//after 5000 millisec msg will be send
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文