2014-12-19 3 views
0

android의 특정 방향에 대한 다음보기를 수동으로 지정하는 방법 또는 구성은 무엇입니까?android에서 특정 방향의 다음보기 ID를 수동으로 지정하는 방법은 무엇입니까?

예를 들어

나는 세 개의 버튼이 있습니다

button1 내가 올바른 방향을 클릭하면 button3

일반적으로는, 내가 button1에서 다음 button2, button3에 초점을 변경하고자하지만, button2 나는 이상한 요구 사항이있는 경우 : 초점을 button1에서 button3으로 변경하고 button2으로 변경하고 싶습니다.

더 일반적인 요구 사항은 초점이 button3 일 때 오른쪽 방향을 클릭하면 button1으로 변경 초점을 원합니다.

어떻게 이러한 요구 사항을 충족시킬 수 있습니까?

+0

'onCreate'에서 필요한 모든 버튼의 뷰 참조를 가져 와서 배열에 저장하십시오. 그런 다음 배열을 반복하고 포커스를 바꿀 수 있습니다. – Panther

+0

@Panther 더 쉬운 방법이 있습니까? 나는 tabindex라는 애트리뷰트를 가진 C#가 TAB을 눌렀을 때 순서를 제어 할 수 있음을 기억한다. – roger

답변

2

android view의 nextFocusRight/Left/Up/Down 속성을 사용해 보셨습니까?

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:nextFocusRight="@+id/button2" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:nextFocusRight="@id/button1" /> 

Java 코드에서 이러한 등록 정보를 설정할 수 있습니다.

Button button1 = (Button) findViewById(R.id.button1); 
    Button button2 = (Button) findViewById(R.id.button2); 
    Button button3 = (Button) findViewById(R.id.button3); 

    button3.setNextFocusRightId(R.id.button1);