2014-08-28 2 views
0

의료용 앱을 만들고 싶습니다. 사람이 '왼쪽 눈'옵션을 선택하면 테스트가 시작됩니다. 결과가 표시되어야합니다. 테스트 결과가 끝나면 다른 쪽 눈을 테스트 할 수있는 옵션이 표시되어야합니다. 이때 '왼쪽 눈'버튼 옵션을 사용 중지해야합니다. 사람이 '오른쪽 눈'을 선택한 다음 테스트를 한 후에는 오른쪽 눈 옵션을 사용 중지해야합니다. 나는 코드를 붙이고있다.android에서 버튼을 사용 또는 사용 중지하려면

public void resetView(){ 

    setContentView(R.layout.duochrometest); 
    setObjects(); 
    int a[] = { R.id.leftEye, R.id.rightEye }; 
    setOnClickListener(a); 
} 

@Override 
public void onClick(View v) { 

    switch (v.getId()) { 
     case R.id.leftEye: 
     case R.id.rightEye: 
      resetTestView(); 
      break;       
     case R.id.testagain: 
      ++testCount; 
      resetView(); 
      break; 
     case R.id.backtoTests: 
      backToTests(); 
      break; 
     default: 
      calculateResult((String) v.getTag()); 
      changeObject(); 
    } 
} 

XML 파일 :

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

    android:orientation="vertical" 
    android:background="@drawable/bg"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:padding="8dp" 
     android:gravity="top" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="@string/duochromeDesc" 
     android:textColor="@color/white"/> 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:padding="2dp" 
     android:orientation="horizontal"> 

     <Button android:id="@+id/leftEye" android:text="@string/lefteye" android:textColor="@color/white" android:layout_width="150dp" android:layout_height="wrap_content" android:background="@drawable/borderlightgray"></Button> 

     <Button android:id="@+id/rightEye" android:text="@string/righteye" android:textColor="@color/white" android:layout_width="150dp" android:layout_height="wrap_content" android:background="@drawable/borderlightgray"></Button> 

     </LinearLayout> 
</LinearLayout> 

이 나를 도와주세요.

답변

1

버튼에 setEnabled (false)를 호출 할 수 있습니다.

+0

위 코드는 어디에 사용해야합니까? – Amdoc

+0

버튼을 신고해야합니다. 'Button button = (Button) findViewById (R.id.button); ' 'button.setEnabled (false);' –

0

레이아웃 파일에서이 버튼을 사용합니다. android : visibility = "gone"버튼에 표시 할 활동 내부에서이 태그를 사용합니다. Button.setVisibility (View.VISIBLE); 이 두 가지 flage를 효과적으로 "사라"와 "눈으로"사용하면 답을 얻을 수 있습니다. #Ravindra

관련 문제