1

GridView のビューを非表示および表示にしようとしています。初めて INVISIBLE AND VISIBLE を呼び出したときに機能させることができますが、その後の試みは機能しません。

  private void flashImageSeq(){
    int i = 0;
    while (i < 9){
        animate(i);         
        ++i;
    }
}

private void startThread() {
  t = new Thread() {
    public void run () {
       try {
        sleep(500);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }
  };

  t.start();
}

private void animate(int position){
    gridview.findViewById(R.id.gridview);
  // imgView is defined in View getView for Adapter code not shown
    ImageView imgView = (ImageView)gridview.getChildAt(position);
    imgView.setVisibility(ImageView.INVISIBLE);
  startThread();
  imgView.setVisibility(ImageView.VISIBLE);
}

flashImageSeq() の 2 回目の呼び出しが機能しない

4

2 に答える 2

0

試す

private void flashImageSeq(){
int i = 0;
while (i < 9){
    animate(i);         
    ++i;
}
}

private void startThread(final ImageView im) {
  t = new Thread() {
    public void run () {
       try {
        sleep(500);
        yourActivity.this.runOnUiThread(new Runnable() {

            public void run() {

            im.setVisibility(ImageView.VISIBLE);

            }
        });
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }
  };

  t.start();
}

private void animate(int position){
    gridview.findViewById(R.id.gridview);
  // imgView is defined in View getView for Adapter code not shown
    ImageView imgView = (ImageView)gridview.getChildAt(position);
    imgView.setVisibility(ImageView.INVISIBLE);
  startThread();

}
于 2012-10-27T18:05:16.617 に答える
0

500ミリ秒間スリープする新しいスレッドを作成していますが、2つのSetVisibility呼び出しが1分の1ミリ秒以内に発生します。

実際にメインスレッドを一時停止するために使用する必要がありますThread.sleep(500)が、これは本当に悪い習慣です!

他の回答が示すように、ループを実行するスレッドを作成し、setVisi 呼び出しが「runOnUIThread」で実行されるようにすることをお勧めします。

于 2012-10-27T18:19:35.020 に答える