代码之家  ›  专栏  ›  技术社区  ›  EGHDK asteri

冻结android应用程序[关闭]

  •  0
  • EGHDK asteri  · 技术社区  · 13 年前

    我想为要冻结的应用程序中的屏幕创建一个计时器。比方说两秒钟。我不希望屏幕对任何屏幕上的按钮点击做出反应。这是“令人不悦”的吗?或者还有别的办法吗。

    我的申请:

    enter image description here

    用户点击:

    enter image description here

    然后我想暂停所有内容两秒钟(这样我的其他按钮听众就不会熄灭),然后我想让听众回去,因为我会把按钮从绿色变回灰色。

    1 回复  |  直到 13 年前
        1
  •  0
  •   digitaljoel    13 年前

    在点击处理程序中,您可以更改颜色,删除所有按钮的onclick监听器,并启动一个后台线程来计时。当后台线程睡眠2分钟后,您可以为所有按钮添加onclick监听器。这样你就不会创建一个完全没有响应的用户界面,但你可以达到禁用按钮的效果。

    public class myListener implements OnClickListener() {
      private boolean ignoreClicks = false;
    
      public void setIgnoreClicks( boolean b ) { 
        this.ignoreClicks = b;
      }
    
      @Override
      public void onClick( View v ) {
        if ( !ignoreClicks ) {
          // use v to get the button, then change the color
          ignoreClicks = true;
          // start a new AsyncTask and give it the listener and the view
          // in doInBackground sleep for 2 seconds
          // in onPostExecute change the color of the button back to normal
          //     (you have a reference to the button because you gave the view to the AsyncTask)
          //   and set ignoreClicks to false in the listener
        }
      }
    }
    

    创建此侦听器的一个实例,并将其用于每个按钮。