0

布局文件:-

  <?xml version="1.0" encoding="utf-8"?>
  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/scroll_bg" >

 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="521dp"
  android:layout_marginBottom="60dp"
  android:background="@drawable/bg" >

<com.deemtech.widgets.MenuLayout
    android:id="@+id/menuTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/txtCustomerDetails"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="140dp"
    android:gravity="center"
    android:text="@string/customer_details"
    android:textColor="#ffffff"
    android:textSize="12sp" />

<EditText
    android:id="@+id/editNameCustomerDetails"
    style="@style/EditText"
    android:layout_below="@+id/txtCustomerDetails"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="12dp"
    android:ems="10"
    android:hint="NAME"
    android:inputType="text" />

<RelativeLayout
    android:id="@+id/innerLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginTop="190dp"
    android:background="@drawable/bg_create_account1x"
    android:gravity="center"
    android:paddingBottom="5dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:paddingTop="8dp" >

    <EditText
        android:id="@+id/editEmailCustomerDetails"
        style="@style/EditText"
        android:layout_alignLeft="@+id/editPhoneCutomerDetails"
        android:layout_alignParentTop="true"
        android:layout_marginTop="52dp"
        android:ems="10"
        android:hint="EMAIL ADDRESS"
        android:inputType="textEmailAddress" />

    <EditText
        android:id="@+id/editPhoneCutomerDetails"
        style="@style/EditText"
        android:layout_below="@+id/editEmailCustomerDetails"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:hint="CONTACT NUMBER"
        android:maxLength="12"
        android:inputType="phone" />

    <!--
    <EditText
        android:id="@+id/editAdditionalInfo"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/editPhoneCutomerDetails"
        android:layout_alignRight="@+id/editPhoneCutomerDetails"
        android:layout_below="@+id/editPhoneCutomerDetails"
        android:layout_marginBottom="60dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/message_additional_box1x"
        android:ems="10"
        android:hint="ADDITIONAL INFO"
        android:inputType="text"
        android:padding="10dp"
        >

        <requestFocus />
    </EditText>
    -->

    <EditText
        android:id="@+id/editAdditionalInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editPhoneCutomerDetails"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/editPhoneCutomerDetails"
        android:layout_below="@+id/editPhoneCutomerDetails"
        android:layout_marginBottom="60dp"
        android:layout_marginTop="8dp"
        android:hint="ADDITIONAL INFO"
        android:background="@drawable/message_additional_box1x"
        android:ems="10"
        android:singleLine="true"
        android:gravity="top"
        android:lines="3"
        android:padding="10dp"
        android:width="150dp" >

        <requestFocus />
    </EditText>
</RelativeLayout>

<Button
    android:id="@+id/btnBackCustomerDetails"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="448dp"
    android:layout_toLeftOf="@+id/btnSubmitCustomerDetails"
    android:background="@drawable/btn_back"
    android:contentDescription="@string/app_name" />

<Button
    android:id="@+id/btnSubmitCustomerDetails"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/editNameCustomerDetails"
    android:layout_marginTop="448dp"
    android:background="@drawable/btn_submit"
    android:contentDescription="@string/app_name" />

我的代码是:-

 editPhoneCustomerDetails.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {

                findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();



            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
            InputMethodManager.HIDE_IMPLICIT_ONLY);


                //((ScrollView) findViewById(R.id.scrollView)).fullScroll(View.FOCUS_DOWN);

                //findViewById(R.id.editPhoneCutomerDetails).requestFocusFromTouch();

               // findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch(); 
            }
            return false;
        }
    });

在这里,我想像当用户从电话详细信息中单击下一个按钮时那样执行,它应该关注最后编辑文本并且还应该显示两个按钮。我的问题是,当我从软输入模式单击下一个按钮时,它会聚焦到后退按钮而不是最后编辑文本。

请帮忙。

注意:- 我必须同时显示两个按钮和最后的编辑文本。

4

1 回答 1

0

这应该可以解决问题:

EditText editNameCustomerDetails = 
    (EditText)findViewById(R.id.editNameCustomerDetails);

editNameCustomerDetails.requestFocus();
于 2013-02-01T10:04:24.553 回答