У меня есть 8 editText в том же LinearLayout.Я хочу, нажав кнопку отмены, чтобы установить фокус на edtNum.
(edtUnitNum.requestFocus ();).
Эта команда работает неправильно и установить фокус на edtSaveMony, но я хочу, чтобы фокусedtunitnum.
В общем, вы не можете сосредоточиться на EditText, который находится в другом Linearlayout.
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/drawer" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.33"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="شماره واحد . . .">
<EditText
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/edt_Members_UnitNum"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:fontFamily="@font/yekan"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="55dp"
android:hint="نام مشترک . . .">
<EditText
android:id="@+id/edt_Members_Name"
android:layout_width="153dp"
android:layout_height="wrap_content"
android:fontFamily="@font/yekan"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="متراژ . . .">
<EditText
android:id="@+id/edt_Members_aria"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:fontFamily="@font/yekan"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="تعداد . . .">
<EditText
android:id="@+id/edt_Members_Qty"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:fontFamily="@font/yekan"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.33"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="مبلغ ذخیره . . .">
<EditText
android:id="@+id/edt_Members_saveMoney"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:fontFamily="@font/yekan"
android:imeOptions="actionNext"
android:inputType="numberDecimal"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="تاریخ . . .">
<EditText
android:id="@+id/edt_Members_date"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:fontFamily="@font/yekan"
android:imeOptions="actionNext"
android:inputType="none"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="155dp"
android:layout_height="wrap_content"
android:hint="توضیحات . . .">
<EditText
android:id="@+id/edt_Members_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/yekan"
android:inputType="text"
android:maxLines="1"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/btn_Members_Insert"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/btn"
android:fontFamily="@font/yekan"
android:gravity="center"
android:text="ثبت"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Members_Cancel"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/btn"
android:fontFamily="@font/yekan"
android:gravity="center"
android:text="انصراف"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Java:
btncancel = (Button) findViewById(R.id.btn_Members_Cancel);
btnInsert = (Button) findViewById(R.id.btn_Members_Insert);
edtUnitNum = (EditText) findViewById(R.id.edt_Members_UnitNum);
edtSaveMoney = (EditText) findViewById(R.id.edt_Members_saveMoney);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
edtUnitNum.clearFocus();
edtUnitNum.setFocusable(true);
edtUnitNum.setFocusableInTouchMode(true);
edtUnitNum.requestFocus();
}
});