steventnorris
steventnorris

Reputation: 5896

Android Next and Done Buttons

I am attempting to have the next and done buttons for two textviews to function normally. Text field 1 should move to text field two on next and text field 2 should close the keyboard/edit view on done. My XML is below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.myapp.LaunchCam"
    tools:ignore="MergeRootFrame" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/autoCompleteTextView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:onClick="onCameraClick"
        android:text="@string/start" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/logo_inline_large" android:contentDescription="@string/logo"/>

        <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="23dp"
        android:ems="10" 
        android:lines = "1"
        android:maxLines = "1"
        android:singleLine = "true"
        android:hint = "@string/enter_first_team_name"
        android:nextFocusDown="@+id/autoCompleteTextView2"/>

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/autoCompleteTextView1"
        android:layout_below="@+id/autoCompleteTextView1"
        android:layout_marginTop="19dp"
        android:ems="10"
        android:lines = "1"
        android:maxLines = "1"
        android:singleLine = "true"
        android:hint = "@string/enter_second_team_name_optional_" />

</RelativeLayout>

When using either of these buttons I get the runtime error

11-05 16:28:11.506: E/View(27606): hasTransientState decremented below 0: unmatched pair of setHasTransientState calls

Upvotes: 0

Views: 914

Answers (2)

Abdallah Alaraby
Abdallah Alaraby

Reputation: 2249

use android:imeOptions and android:imeActionId to do this. read about the available options

Upvotes: 1

liltof
liltof

Reputation: 2192

This can be done easily if I understood what you want, but I'm not sure : if you want to quicky move to the next textfield, Android provides imeOptions : the Enter key of the keyboard will change to an arrow to move to the next text field with android:imeOptions="actionNext", or to a "Go" button when it's the last one with android:imeOptions="actionGo" or android:imeOptions="actionDone". So you don't need to put a next button in your app. See this page of the documentation for mor information https://developer.android.com/training/keyboard-input/style.html

Upvotes: 4

Related Questions