Program Club

XML 레이아웃에서 "탭 순서"를 설정할 수 있습니까?

proclub 2021. 1. 5. 08:22
반응형

XML 레이아웃에서 "탭 순서"를 설정할 수 있습니까?


소프트 키보드에 탭 키가있는 태블릿 사용자가 있습니다. 테이블보기를 사용하고 있으며 현재 행 아래에 EditText 필드가있는 한 행에 3 개의 EditText 필드가 있습니다.

사용자가 탭을 누르면 오른쪽의 다음 필드가 아니라 아래의 다음 필드로 이동합니다.

레이아웃에 탭 순서를 설정하는 방법이 있습니까 아니면 프로그래밍 방식으로 만 수행됩니까?

Java로만 수행 할 수 있다면 정확히 어떻게 수행됩니까?

NextFocusRight에 대한 팁을 주셔서 감사하지만 작동하지 않는 것 같습니다 (또는 내가 잘못한 것 같습니다)

다음은 내가 사용한 코드입니다. 내 에뮬레이터에 "다음"버튼을 표시하려면 imeoptions를 추가해야합니다. 내가 한 방식에 문제가 있습니까?

    <EditText 
android:id="@+id/bikeHHT"
android:layout_width="50dip"
android:layout_height="40dip"
android:textSize="14px"
android:maxLength="2"
android:nextFocusLeft="@+id/bikeMMT"
android:imeOptions="actionNext"
android:layout_column="1"/>
<EditText 
android:id="@+id/bikeMMT"
android:layout_width="50dip"
android:layout_height="40dip"
android:textSize="14px"
android:nextFocusRight="@+id/bikeSST"
android:imeOptions="actionNext"
android:maxLength="2"/>

교체 android:nextFocusLeftandroid:nextFocusDown. "다음"소프트 버튼 또는 TAB 키는 왼쪽이나 오른쪽이 아닌 다음 "아래"초점을 찾고 있습니다.


또한 귀하의 참고 자료에서 다음 사항을 확인했습니다.

android:nextFocusRight="@+id/bikeSST"

참조하는 요소가 .xml 파일에서 더 낮은 경우 해당 ID를 아직 정의하지 않은 경우 "+"문자가 필요합니다.

그렇지 않으면 이미 위에 정의되어 있거나 포함되어 있으면 "+"문자를 생략 할 수 있습니다.

android:nextFocusRight="@id/bikeSST"

이미 존재해야하는 ID를 참조 할 때 "+"를 사용하지 않는 이점은 IDE 및 Lint 검사가 오류 사례를 감지 할 수 있다는 것입니다. 실제로 존재 하지 않는 ID를 참조하고 있다는 것 입니다.

"+"를 포함하면 존재하지 않는 경우 생성하고이 검사를 수행 할 수 없습니다.


android:imeOptions="actionNext"EditText의 속성을 확인 했습니까 ?

가상 키보드에서 Enter 키의 이름을 "Next"로 바꾸고 클릭하면 포커스가 다음 필드로 이동합니다.

레이아웃에서 다음과 같은 작업을 수행합니다.

<EditText
    ...
    android:text="Field 1"
    android:imeOptions="actionNext" />
<EditText
    ...
    android:text="Field 2"
    android:imeOptions="actionNext" />

그리고 자바

TextView field2 = (TextView) field1.focusSearch(View.FOCUS_RIGHT);
field2.requestFocus();

다음에 포커스를 요청할 필드를 결정하는 것은 사용자에게 달려 있습니다.


나를 위해 android:nextFocusUp, android:nextFocusRight, android:nextFocusDownandroid:nextFocusLeft작동하지만,하지 않은 android:nextFocusForward일을했다.

키보드 탐색 지원, 탭 탐색 처리를 참조하십시오 .


더 나은 방법이 있습니다. EditText사용자가 완료 할 때 마다 커서를 자동으로 이동하는 레이아웃에 넣을 수있는 XML 인수가 있습니다. 이를 통해 훨씬 더 쉽게 양식을 구현할 수 있습니다.

문제는, 빌어 먹을 인생이 뭔지 기억하기 때문이야

Be sure to check out the android:nextFocus* xml properties. Normal form action is to go down. But perhaps there's a button to the right that you'd like to receive next focus (like hitting enter or similar).

http://developer.android.com/reference/android/view/View.html#attr_android:nextFocusDown

There's also some programatic options available:

http://developer.android.com/reference/android/view/View.html#setNextFocusDownId(int)


You might be looking for the attributes android:nextFocusRight, android:nextFocusLeft, android:nextFocusUp, and android:nextFocusDown. If the default behavior of the tab button is moving focus down to the second row, then I would think you could set android:nextFocusDown to the id of the view that you want to get focus next. Then when the user presses tab it wold move focus to whatever view you specify, even though in this case it happens to be to the right of the current view, and not below it.


Replace android:nextFocusLeft with android:nextFocusForward.

ReferenceURL : https://stackoverflow.com/questions/5048586/can-you-set-tab-order-in-xml-layout

반응형