在Android中处理SoftKeypad的完成和下一步?

Ami*_*mit 5 android android-widget

我有一个简单的登录活动有两个编辑文本文件,用于用户名和密码..现在我想实现以下两个功能,

  1. 如果在焦点位于userNameText时触摸了下一个按钮,则光标应移动到第二个editText字段,即passwordText ..
  2. 如果在光标位于passwordText字段时按下完成,我想调用一个在OK按钮的监听器内调用的函数.

在此输入图像描述 在此输入图像描述

我的XML文件看起来像这样

<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>
Run Code Online (Sandbox Code Playgroud)

use*_*730 1

anDroider 请求 - 没有答案

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo" />

        <EditText
            android:id="@+id/loginuser"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:ems="10"
            android:hint="@string/username_string"
            android:inputType="textEmailAddress" >

        </EditText>

        <EditText
            android:id="@+id/loginpass"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/password_string"
            android:inputType="textPassword" />

        <Button
            android:id="@+id/loginbtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:clickable="true"
            android:text="Login" />

    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

编辑:这部分是一个答案

使用OnEditorActionListener并监听完成键被按下。