2012-06-13 3 views
0

나는 안드로이드 프로젝트에서 일하고 있습니다. 배열에 추가 할 레이아웃 내의 각 컨트롤을 반복하고 있는데,이 배열을 배열을 통해 반복하고 일부를 수행하는 함수에 전달하고 있습니다. 이벤트를 제어합니다. 제어 유형이 무엇인지 판별 할 수있는 방법이 있습니까? psuedo 코드로 이런 식으로 될 것입니다.ID에서 안드로이드 컨트롤 유형을 찾으십시오

void getControlType(List<View> myControls) 
    { 
     foreach (List<View> control in myControls) 
     { 
      string controlType = getControlType(control); 
      if (controlType == "Button") 
      { 
        //do something on the button 
      } 
     } 
} 

답변

0

이 아니 일반적으로 좋은 디자인 패턴 동안, 이것은 작동합니다 :

foreach (List<View> control in myControls) 
{ 
    if (control instanceof Button) 
    { 
     Button button = (Button)control; 
     //do something on the button 
    } 
} 
관련 문제