2017-09-28 1 views
0

해결하기가 복잡해 보이지는 않지만 내가하는 일과 상관없이 문제가 생겼다.내 화면이 새로 고침하고 싶지 않다.

여기 내 문제 야 : 나는

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/backgroundshape"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/text_timer" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:textColor="#f44242" 
    android:textSize="95dp" 
    android:textStyle="bold" 
    /> 

<ImageView 
    android:id="@+id/image_1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="25dp" 
    android:layout_centerVertical="true"/> 

<ImageView 
    android:id="@+id/image_2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="25dp" 
    android:layout_centerVertical="true"/> 

</RelativeLayout> 

점은 다른 뷰의 인스턴스를 시작하는 모든 화면을 마지막 이미지 뷰를 클릭하는 것입니다이 레이아웃을 가지고있다.

는 상관없이 나는 (...) (무효화) 할 것을
public class GameScreen extends Activity { 

ImageView imgEmpty, img1, img2; 
TextView tvTimer; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.layout_second); 

    img1 = (ImageView)findViewById(R.id.image_1); 

    img2 = (ImageView)findViewById(R.id.image_2); 

    imgEmpty = (ImageView)findViewById(R.id.image_empty); 
    imgEmpty.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      img1.setBackgroundResource(R.drawable.feuille); 
      img2.setBackgroundResource(R.drawable.feuille); 
      tvTimer.setTextSize(95); 
      for(int i=0; i<3; i++) { 
       imgEmpty.setVisibility(View.GONE); 
       try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); Log.d("Ratatataaa","Y passe pas !!!!"); } 
       tvTimer.setText(""+i); 
       view.invalidate(); 
      } 
     } 
    }); 

    tvTimer = (TextView)findViewById(R.id.text_timer); 
    tvTimer.setTextSize(50); 
    tvTimer.setText("Ready ?"); 
} 
} 

화면 만 온 클릭 (보기보기)의 말

도와주세요에서 새로 고침 : 여기에 내가 할 어때
+2

예상되는 행동이 전혀 분명하지 않다,() 왜'무효화를) (setVisibility'하려고'되고, 또한 '같은보기를 –

+0

을 무슨 일이 일어나고 있는지 당신이 원하는 어떤 설명 세 번 반복 루프. – ZeekHuge

+0

@ Pavneet_Singh "imgEmpty"를 클릭하면 2 개의 다른 ImageView가 원하는 이미지를 표시하고 TextView는 0, 1, 2를 인쇄해야합니다. 예상되는 동작은 이미지와 텍스트가 표시되지만 fonction의 끝, 나는 나의 2 개의 심상 및 "2"가 있고 나의 2 개의 심상 및 0 및 그 때 1 2 그 후에 – Kolopox

답변

0

거기에 나쁜 영향이 있습니다. 예를 들어 sleep()을 주 스레드로 사용하고 TextView을 잘못된 지점에서 초기화합니다.

이 대신보십시오 :

.... 
img1 = (ImageView)findViewById(R.id.image_1); 
img2 = (ImageView)findViewById(R.id.image_2); 

tvTimer = (TextView)findViewById(R.id.text_timer); 
tvTimer.setTextSize(50); 
tvTimer.setText("Ready ?"); 

imgEmpty = (ImageView)findViewById(R.id.image_empty); 
imgEmpty.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     img1.setBackgroundResource(R.drawable.feuille); 
     img2.setBackgroundResource(R.drawable.feuille); 
     tvTimer.setTextSize(95); 
     imgEmpty.setVisibility(View.GONE); 
     view.invalidate(); 
     new CountDownTimer(3000, 1000) { 
      @Override 
      public void onTick (long millisUntilFinished) { 
       tvTimer.setText("" + ((int)(3000 - millisUntilFinisehd)/1000)); 
      } 

      @Override 
      public void onFinish() {} 
     }; 
    } 
}); 
.... 
관련 문제