Android 编辑文本焦点
我有四个编辑文本。当我在第一个编辑文本中输入一些值时,如果它没有焦点,则检查一个条件。现在,如果条件为false,则焦点应放在第一个编辑文本上,但它位于最后一个文本中 我想如果条件Android 编辑文本焦点,android,focus,android-edittext,Android,Focus,Android Edittext,我有四个编辑文本。当我在第一个编辑文本中输入一些值时,如果它没有焦点,则检查一个条件。现在,如果条件为false,则焦点应放在第一个编辑文本上,但它位于最后一个文本中 我想如果条件strRO.equals(“12345”)失败,那么重点应该放在第一个编辑文本上。 但目前它在最后一次编辑文本 当条件失败时,请帮助我。 <LinearLayout android:id="@+id/footer" android:layout_width="fill_parent
strRO.equals(“12345”)
失败,那么重点应该放在第一个编辑文本上。
但目前它在最后一次编辑文本
当条件失败时,请帮助我。
<LinearLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:layout_alignParentBottom="true"
android:background="@layout/footer_repeat"
android:orientation="vertical" >
</LinearLayout>
<!-- Footer Ends -->
<!-- Login Form -->
<LinearLayout
android:id="@+id/midheader"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_below="@id/header"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:onClick="layoutClick"
android:padding="10dip" >
<!-- Email Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/stk_location"
android:textColor="#ffffff"
android:textSize="20dip" />
<Spinner
android:id="@+id/cmbstock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dip"
android:layout_marginTop="5dip"
android:textColor="#ff0000"
android:textSize="50dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/RONO"
android:textColor="#ffffff"
android:textSize="20dip" />
<EditText
android:id="@+id/txtRO"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dip"
android:layout_marginTop="5dip"
android:background="@drawable/back"
android:focusableInTouchMode="true"
android:inputType="text"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="#000000"
android:textSize="35dip"
android:width="@dimen/padding_large" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ITEMNO"
android:textColor="#ffffff"
android:textSize="20dip" />
<EditText
android:id="@+id/txtItemNO"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dip"
android:layout_marginTop="5dip"
android:background="@drawable/back"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="text"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="#000000"
android:textSize="35dip"
android:width="@dimen/padding_large" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ITEMDESC"
android:textColor="#ffffff"
android:textSize="20dip" />
<EditText
android:id="@+id/txtItemDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dip"
android:layout_marginTop="5dip"
android:background="@drawable/back"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="text"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="#000000"
android:textSize="35dip"
android:width="@dimen/padding_large" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/BIN"
android:textColor="#ffffff"
android:textSize="20dip" />
<EditText
android:id="@+id/txtBin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dip"
android:layout_marginTop="5dip"
android:background="@drawable/back"
android:inputType="text"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="#000000"
android:textSize="35dip"
android:width="@dimen/padding_large" />
<LinearLayout
android:id="@+id/botbtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="5dip"
android:paddingLeft="5dip"
android:paddingTop="5dip" >
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="5dip"
android:layout_marginTop="2dip"
android:background="@drawable/bgbutton"
android:height="60dip"
android:onClick="onBtnClicked"
android:text="@string/btnSubmit"
android:textColor="#000000"
android:textSize="30dip"
android:width="240dip" />
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="5dip"
android:background="@drawable/bgbutton"
android:height="60dip"
android:onClick="onBtnResetClicked"
android:text="@string/btnReset"
android:textColor="#000000"
android:textSize="30dip"
android:width="240dip" />
</LinearLayout>
</LinearLayout>
试试这个
edittext.requestFocus();
试试看:
if(!strRO.equals("12345")){
editText1.requestFocus();
editText4.clearFocus();
}
firsteditText.requestFocus()
尝试了所有建议的答案,但Last EditText未离开焦点在两个编辑文本上可见,但当我在最后一个文本中键入更改时。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能会无效。尝试了所有建议的答案,但最后一个编辑文本未离开焦点光标在两个编辑文本上可见,但当我在最后一个编辑文本中键入更改时,先生,但我这边什么也没发生SirI我已经尝试过多次,每次都很好,确保已将其正确地放入Java代码中:EditText firsteditText=(EditText)findViewById(R.id.txtRO);firsteditText.requestFocus();并在第一个编辑文本中尝试这行代码:android:focusable=“true”
<LinearLayout android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px" >
<requestFocus />
</LinearLayout>
EditText firsteditText=(EditText)findViewById(R.id.edt1);