2011-11-10 3 views
1

Android 앱을 만들고 있습니다. 이상한 점이 있습니다. 나는 5 탭에 대한 ViewFlipper가 필요합니다. 나는 5 개의 버튼이있는 페이지 레이아웃을 만들었다. OnClickListener을 사용하고 뒤집기 탭이 제대로 작동하지만 버튼을 넣으려면 setPressed(true)해야하고 그럴 수는 없습니다. 재 페인트 문제가 있습니다. 나는 그물에 해결책을 찾았지만 다른 누구도이 문제가 없습니까? 나는 무엇을 잘못 했는가? 는, setEnabledViewFlipper에서 고정 버튼을 누르십시오 (Android)

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    factory = getLayoutInflater(); 
     skin = factory.inflate(R.layout.skin_tab_raspored, null); 

    vremelayout = (LinearLayout) skin.findViewById(R.id.vreme); 
    infolayout = (LinearLayout) skin.findViewById(R.id.info); 

     buttons[0] = (Button) skin.findViewById(R.id.pon); 
     buttons[1] = (Button) skin.findViewById(R.id.uto); 
     buttons[2] = (Button) skin.findViewById(R.id.sre); 
     buttons[3] = (Button) skin.findViewById(R.id.cet); 
     buttons[4] = (Button) skin.findViewById(R.id.pet); 

     buttons[0].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(0); 
       buttons[currentTab].setPressed(false); 
       currentTab = 0; 
       buttons[0].setPressed(true); 
      } 
     }); 
     buttons[1].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(1); 
       buttons[currentTab].setPressed(false); 
       currentTab = 1; 
       buttons[1].setPressed(true); 
      } 
     }); 
     buttons[2].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(2); 
       buttons[currentTab].setPressed(false); 
       currentTab = 2; 
       buttons[2].setPressed(true); 
      } 
     }); 
     buttons[3].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(3); 
       buttons[currentTab].setPressed(false); 
       currentTab = 3; 
       buttons[3].setPressed(true); 
      } 
     }); 
     buttons[4].setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       flipper_info.setDisplayedChild(4); 
       buttons[currentTab].setPressed(false); 
       currentTab = 4; 
       buttons[4].setPressed(true); 
      } 
     }); 

     buttons[0].setPressed(true); 

     add_time(); //adding content to vremelayout 

     flipper_info = new ViewFlipper(this); 

     flipper_info.addView(this.addContentToInfo(Dan.pon));//adding content to infolayout 
     flipper_info.addView(this.addContentToInfo(Dan.uto)); 
     flipper_info.addView(this.addContentToInfo(Dan.sre)); 
     flipper_info.addView(this.addContentToInfo(Dan.cet)); 
     flipper_info.addView(this.addContentToInfo(Dan.pet)); 

     infolayout.addView(flipper_info); 

     setContentView(skin); 
} 

답변

1

사용은() 배경 색상 변경은 토글 버튼을 사용하는 경우, 당신이 온/오프 상태에 대한 선택을 설정 할 수 있습니다

  flipper_info.setDisplayedChild(0); 
      buttons[currentTab].setEnabled(true); 
      currentTab = 0; 
      buttons[0].setEnabled(false); 

또는

마다에 ClickListener 내부 setPressed의 insted ... clickListener 내부의 상태를 전환합니다.

+0

여기에 Tnx가 있지만 이것을 사용할 수 없습니다. 나는 버튼의 변경 bgd와 그 사용 선택기에 필요합니다. 선택기 (항목)에서이 활성화 된 속성을 가져올 수 없습니다? – CoYoTe

+0

확인 편집 됨 응답 –

+0

나중에 ToggleButton 작동 ... tnx ... 다른 네 개의 버튼에 대해서도 enable과 setChecked를 사용해야합니다. 버튼의 일부 라디오 버튼이 필요합니다. P 결국 라디오 버튼을 사용할 수 있음을 알았습니다. 그 (것)들을 나의 피부 추가하십시오 : P – CoYoTe

관련 문제