runOnUiThread(new Runnable() { 标点符号(令牌)问题

发布于 2024-12-20 07:52:34 字数 1081 浏览 2 评论 0原文

不知怎的,它不起作用,根据我的说法,应该是这样的:

public void Splash(){
    Timer timer= new Timer();

    timer.schedule(new TimerTask(){ 

    MexGame.this.runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);
      } //Closes run()

      }); //Closes runOnUiThread((){})

  },SplashTime); //Closes the Timeratask((){})

} //closes Splash()

有人知道我错过了什么吗?

正式评论 我知道这个问题很愚蠢,或者也许我正在做一些不可能的事情,但我尝试了所有合乎逻辑的可能性。所以可能错过了一些东西或者我正在尝试做一些不可能的事情。 你能帮我一下吗? 我正在尝试使用以下代码,但这会带来令牌问题:

 Timer timer= new Timer();
   timer.schedule(new TimerTask(){

     runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);}

      });}

  },SplashTime);

如果我阻止 runOnUiThread 它会崩溃,因为我试图从另一个线程调整 UI,但至少没有令牌问题,有人知道吗?

   Timer timer= new Timer();


  timer.schedule(new TimerTask(){

//   runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);}

    //  });}

  },SplashTime);

Somehow it doesn't work, according to me it should be this:

public void Splash(){
    Timer timer= new Timer();

    timer.schedule(new TimerTask(){ 

    MexGame.this.runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);
      } //Closes run()

      }); //Closes runOnUiThread((){})

  },SplashTime); //Closes the Timeratask((){})

} //closes Splash()

Anybody any idea where I'm missing something?

FORMAL COMMENT
I know silly issue, or maybe I'm doing something impossible, but I tried all the logical possibilities. So probably missing something or I'm trying to do something that is not possible.
Can you please help me out.
I'm trying to use the following code, but that gives token issues:

 Timer timer= new Timer();
   timer.schedule(new TimerTask(){

     runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);}

      });}

  },SplashTime);

If I block out the runOnUiThread it crashes since I'm trying to adapt the UI from another thread, but at least no token issue, anybody any idea?:

   Timer timer= new Timer();


  timer.schedule(new TimerTask(){

//   runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);}

    //  });}

  },SplashTime);

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

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

发布评论

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

评论(2

聚集的泪 2024-12-27 07:52:34

TimerTask 和 Runnable 都要求您实现 run 方法,因此您需要两个 run 方法。

此外,如果将 Runnable 的构造与 TimerTask 的构造分开,您的代码将更易于阅读。

   final Runnable setImageRunnable = new Runnable() {
        public void run() {
             splashImage.setImageDrawable(aktieknop);
        }
    };

    TimerTask task = new TimerTask(){
        public void run() {
            getActivity().runOnUiThread(setImageRunnable);
        }
    };

    Timer timer = new Timer();
    timer.schedule(task, splashTime);

Both the TimerTask and the Runnable require you to implement a run method, so you'll need two run methods.

Also your code will be more easy to read if you separate the construction of the Runnable from the construction of the TimerTask.

   final Runnable setImageRunnable = new Runnable() {
        public void run() {
             splashImage.setImageDrawable(aktieknop);
        }
    };

    TimerTask task = new TimerTask(){
        public void run() {
            getActivity().runOnUiThread(setImageRunnable);
        }
    };

    Timer timer = new Timer();
    timer.schedule(task, splashTime);
别想她 2024-12-27 07:52:34

SplashTime 之前有多余的“}”。您注释了一个开头“{”和两个结尾“}”,因此您的原始代码有一个不需要的“}”。

Timer timer= new Timer();
timer.schedule(new TimerTask(){
        runOnUiThread(new Runnable() {
            public void run(){
                SplashImage.setImageDrawable(aktieknop);
            }   //closes run(){}         
        });     //closes runOnUiThread( Runnable(){ }); 
    },          //closes TimerTask(){}
    SplashTime);

You have excess "}" before SplashTime. You've commented one openning "{" and two closing "}", so your original code have one unrequired "}".

Timer timer= new Timer();
timer.schedule(new TimerTask(){
        runOnUiThread(new Runnable() {
            public void run(){
                SplashImage.setImageDrawable(aktieknop);
            }   //closes run(){}         
        });     //closes runOnUiThread( Runnable(){ }); 
    },          //closes TimerTask(){}
    SplashTime);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文