在for循环中等待特定时间的程序

时间:2015-07-28 09:25:59

标签: android

我想在完成后每次等待我的节目1秒钟   for ( j = i + 1; j <= cnt; j++)循环。

我用过

  try
  { 
     Thread.sleep(1000); 
  }
  catch(InterruptedException e){ }

但我的程序每次都等不到1秒......在排序前等待总共1 * cnt秒。请帮忙。

代码:

      for ( i = 1; i <= cnt; i++) {
          for ( j = i + 1; j <= cnt; j++) {
            int id1,id2;

            StringBuilder name2 = new StringBuilder("button" + j);
            StringBuilder name1 = new StringBuilder("button" + i);
            String pack = getPackageName();
            id1 = getResources().getIdentifier(name1.toString(), "id", pack);
            id2 = getResources().getIdentifier(name2.toString(), "id", pack);
            Button bnn1 = (Button) findViewById(id1);

            Button bnn2 = (Button) findViewById(id2);

            String s1 = bnn1.getText().toString();
            String s2 = bnn2.getText().toString();
            int num1 = Integer.parseInt(s1);
            int num2 = Integer.parseInt(s2);
            if (num1 > num2) {
                bnn1.setText(s2);
                bnn2.setText(s1);
            }

        }
             //time

        try{ Thread.sleep(1000); }catch(InterruptedException e){ }



    }

0 个答案:

没有答案