I have a simple login Activity having two edit texts fileds, for username and password.. Now I want to achieve following two features,
- If next button is touched while focus is on userNameText, the cursor should move to the second editText field i.e. passwordText..
- If done is pressed while cursor is on passwordText field the, I want to call a function which is called inside the OK Button’s listener.
My XML file looks like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/online" >
<TextView
android:id="@+id/userNamelbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/userNameLbl" />
<EditText
android:id="@+id/userNametxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/userNamelbl"
android:background="@android:drawable/editbox_background"
android:hint="@string/userNameTxt"
android:maxLines="1"
android:nextFocusDown="@+id/passwordtxt"
android:singleLine="true" />
<TextView
android:id="@+id/passwordlbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/userNametxt"
android:text="@string/passwordLbl" />
<EditText
android:id="@+id/passwordtxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/passwordlbl"
android:background="@android:drawable/editbox_background"
android:hint="@string/passwordTxt"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
<Button
android:id="@+id/okBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/passwordtxt"
android:layout_marginLeft="10dip"
android:text="@string/okLbl" />
<Button
android:id="@+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/okBtn"
android:layout_toLeftOf="@id/okBtn"
android:text="@string/cancelLbl" />
</RelativeLayout>
Requested by anDroider – Not an answer
EDIT: This part is an answer
Use
OnEditorActionListenerand listen for the done key to be pressed.