- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
接下来我有多个 Edittexts,我在 xml 中添加了 nextFocus 值。
但是根据未成年人复选框值的状态,一个编辑文本是可见的还是不可见的。所以我需要在 YYYY 编辑文本之后动态地关注它。 但动态 requestFocus() 不起作用。
点击下一步我需要做什么
此电子邮件 View 仅在未选中 18 岁以下复选框时可见。
What happends on next button click after YYYY edittext : control goes to username Edittext. I cant use FocusNext in xml as the app crashes whenever the email textview is GONE
dobYearEt.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("focus","on yyyy");
if (actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_ACTION_NEXT) {
Log.i("focus",isUnderAge+"");
if(isUnderAge){
username_reg_ev_dob_row.setFocusableInTouchMode(true);
username_reg_ev_dob_row.requestFocus();
}else{
// NOTHING HAPPENS
// email_ev.setFocusableInTouchMode(true);
// dobYearEt.clearFocus();
email_ev.requestFocus();
// InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// mgr.showSoftInput(email_ev, InputMethodManager.SHOW_IMPLICIT);
}
return false;
}
XML
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register"
android:layout_marginLeft="@dimen/sign_up_left_right_margin"
android:layout_marginRight="@dimen/sign_up_left_right_margin"
android:layout_marginTop="@dimen/sign_up_user_name_top_margin">
<!--<RelativeLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<EditText
android:id="@+id/firstname_ev"
style="@style/RegisterViewStyle"
android:hint=" FIRST NAME:"
android:textCursorDrawable="@null"
android:nextFocusForward="@+id/middle_ev"
android:nextFocusRight="@+id/middle_ev"
android:nextFocusDown="@+id/middle_ev"
android:nextFocusLeft="@+id/middle_ev"
android:nextFocusUp="@+id/middle_ev"/>
<View
android:layout_width="@dimen/sign_up_names_sep_width"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/middle_ev"
style="@style/RegisterViewStyle"
android:hint=" MIDDLE INITIAL:"
android:textCursorDrawable="@null"
android:nextFocusForward="@+id/lastname_ev"
android:nextFocusRight="@+id/lastname_ev"
android:nextFocusDown="@+id/lastname_ev"
android:nextFocusLeft="@+id/lastname_ev"
android:nextFocusUp="@+id/lastname_ev"/>
<View
android:layout_width="@dimen/sign_up_names_sep_width"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/lastname_ev"
style="@style/RegisterViewStyle"
android:hint=" LAST NAME:"
android:textCursorDrawable="@null"
android:nextFocusForward="@+id/dob_mm_et"
android:nextFocusRight="@+id/dob_mm_et"
android:nextFocusDown="@+id/dob_mm_et"
android:nextFocusLeft="@+id/dob_mm_et"
android:nextFocusUp="@+id/dob_mm_et"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/under18_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/raffle_blue_color"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/under18_tv"
android:text="I'm under 18 and/or don't have an email?"/>
</LinearLayout>
<LinearLayout
android:id="@+id/dob_parent_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--android:weightSum="2"-->
<LinearLayout
style="@style/RegisterViewStyle2"
android:id="@+id/dob_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:layout_weight="1"
android:orientation="horizontal">
<!--style="@style/RegisterViewStyle2"-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DOB:"
android:textColor="@color/edit_text_hint_color"
android:id="@+id/dob_label_tv"
/>
<!--<EditText-->
<!--android:id="@+id/dob_dd_et"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:background="@android:color/transparent"-->
<!--android:hint="_ _"-->
<!--android:textCursorDrawable="@null"-->
<!--android:inputType="number"-->
<!--android:maxLength="2"-->
<!--android:nextFocusForward="@+id/dob_mm_et"-->
<!--android:nextFocusRight="@+id/dob_mm_et"-->
<!--android:nextFocusDown="@+id/dob_mm_et"-->
<!--android:nextFocusLeft="@+id/dob_mm_et"-->
<!--android:nextFocusUp="@+id/dob_mm_et"/>-->
<EditText
android:id="@+id/dob_mm_et"
style="@style/RegisterViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hint="MM"
android:textCursorDrawable="@null"
android:inputType="number"
android:maxLength="2"
android:nextFocusForward="@+id/dob_dd_et"
android:nextFocusRight="@+id/dob_dd_et"
android:nextFocusDown="@+id/dob_dd_et"
android:nextFocusLeft="@+id/dob_dd_et"
android:nextFocusUp="@+id/dob_dd_et"/>
<TextView
android:textColor="@color/edit_text_hint_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" / "/>
<!--<EditText-->
<!--android:id="@+id/dob_mm_et"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:background="@android:color/transparent"-->
<!--android:hint="_ _"-->
<!--android:inputType="number"-->
<!--android:textCursorDrawable="@null"-->
<!--android:maxLength="2"-->
<!--android:nextFocusForward="@+id/dob_yyyy_et"-->
<!--android:nextFocusRight="@+id/dob_yyyy_et"-->
<!--android:nextFocusDown="@+id/dob_yyyy_et"-->
<!--android:nextFocusLeft="@+id/dob_yyyy_et"-->
<!--android:nextFocusUp="@+id/dob_yyyy_et"/>-->
<EditText
android:id="@+id/dob_dd_et"
style="@style/RegisterViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hint="DD"
android:inputType="number"
android:textCursorDrawable="@null"
android:maxLength="2"
android:nextFocusForward="@+id/dob_yyyy_et"
android:nextFocusRight="@+id/dob_yyyy_et"
android:nextFocusDown="@+id/dob_yyyy_et"
android:nextFocusLeft="@+id/dob_yyyy_et"
android:nextFocusUp="@+id/dob_yyyy_et"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" / "
android:textColor="@color/edit_text_hint_color"/>
<EditText
style="@style/RegisterViewStyle"
android:id="@+id/dob_yyyy_et"
android:layout_width="wrap_content"
android:textCursorDrawable="@null"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hint="YYYY"
android:inputType="number"
android:maxLength="4"
/>
<!--android:nextFocusForward="@+id/email_ev"-->
<!--android:nextFocusRight="@+id/email_ev"-->
<!--android:nextFocusDown="@+id/email_ev"-->
<!--android:nextFocusLeft="@+id/email_ev"-->
<!--android:nextFocusUp="@+id/email_ev"-->
</LinearLayout>
<EditText
android:id="@+id/email_ev"
style="@style/RegisterViewStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:layout_weight="1"
android:hint=" EMAIL:"
android:textCursorDrawable="@null"
/>
<!--android:nextFocusForward="@+id/password_reg_ev"-->
<!--android:nextFocusRight="@+id/password_reg_ev"-->
<!--android:nextFocusDown="@+id/password_reg_ev"-->
<!--android:nextFocusLeft="@+id/password_reg_ev"-->
<!--android:nextFocusUp="@+id/password_reg_ev"-->
<!--style="@style/RegisterViewStyle2"-->
<EditText
android:id="@+id/username_reg_ev_dob_row"
style="@style/RegisterViewStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:layout_weight="1"
android:hint=" USERNAME:"
android:textCursorDrawable="@null"
android:visibility="gone"
android:nextFocusForward="@+id/password_reg_ev"
android:nextFocusRight="@+id/password_reg_ev"
android:nextFocusDown="@+id/password_reg_ev"
android:nextFocusLeft="@+id/password_reg_ev"
android:nextFocusUp="@+id/password_reg_ev"/>
</LinearLayout>
<EditText
android:id="@+id/username_reg_ev"
style="@style/RegisterViewStyle2"
android:layout_below="@+id/email_ev"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:hint=" USERNAME:"
android:textCursorDrawable="@null"
android:nextFocusForward="@+id/password_reg_ev"
android:nextFocusRight="@+id/password_reg_ev"
android:nextFocusDown="@+id/password_reg_ev"
android:nextFocusLeft="@+id/password_reg_ev"
android:nextFocusUp="@+id/password_reg_ev"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/password_reg_ev"
style="@style/RegisterViewStyle2"
android:layout_below="@+id/username_reg_ev"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:hint=" PASSWORD:"
android:layout_marginRight="2dp"
android:textCursorDrawable="@null"
android:inputType="textPassword"
android:nextFocusForward="@+id/confirm_password_reg_ev"
android:nextFocusRight="@+id/confirm_password_reg_ev"
android:nextFocusDown="@+id/confirm_password_reg_ev"
android:nextFocusLeft="@+id/confirm_password_reg_ev"
android:nextFocusUp="@+id/confirm_password_reg_ev"/>
<EditText
android:id="@+id/confirm_password_reg_ev"
style="@style/RegisterViewStyle2"
android:layout_below="@+id/password_reg_ev"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:hint=" CONFIRM PASSWORD:"
android:textCursorDrawable="@null"
android:inputType="textPassword"
android:nextFocusForward="@+id/group_code_reg_ev"
android:nextFocusRight="@+id/group_code_reg_ev"
android:nextFocusDown="@+id/group_code_reg_ev"
android:nextFocusLeft="@+id/group_code_reg_ev"
android:nextFocusUp="@+id/group_code_reg_ev"/>
</LinearLayout>
<EditText
android:id="@+id/group_code_reg_ev"
style="@style/RegisterViewStyle2"
android:layout_below="@+id/confirm_password_reg_ev"
android:layout_marginTop="@dimen/sign_up_field_sep_margin"
android:textCursorDrawable="@null"
android:hint=" GROUP CODE(OPTIONAL):"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/terms_conditions_signup_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/raffle_blue_color"
/>
<TextView
android:id="@+id/terms_conditions_register_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/terms_conditions"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/register_btn_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/registration_message"
android:layout_marginBottom="6dp"
android:layout_marginTop="@dimen/sign_up_btn_top_margin"
android:background="@color/raffle_blue_color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="@+id/register_tv"
android:padding="6dp"
android:text="REGISTER"
android:textColor="@android:color/white"
android:textSize="@dimen/sign_up_edit_text_size"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
我已经引用了各种解决方案,但没有任何效果
Set next EditText focused and editable on KEY_DOWN
最佳答案
发生的事情是我从 onEditorAction 返回 false - 因此默认编辑器操作也背靠背执行,焦点立即从电子邮件 editText 移开。现在我返回 true 并且未执行默认操作。它现在工作正常。
dobYearEt.setOnEditorActionListener(new EditText.OnEditor ActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("focus","on yyyy");
if (actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_ACTION_NEXT) {
Log.i("focus",isUnderAge+"");
if(isUnderAge){
username_reg_ev_dob_row.setFocusableInTouchMode(true);
username_reg_ev_dob_row.requestFocus();
}else{
email_ev.requestFocus();
}
return true ; // NOW WORKS
// return false;
}
关于android - Edittext requestFocus() 动态不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37293470/
我正在尝试从 TextInputControl 调用 requestFocus 方法。没有成功。我想在打开新选项卡时将焦点放在 TextInputControl 上。我这样做: tab.setCont
在我的 Java Swing 应用程序中,Reuestfocus 方法在构造函数中不起作用。但如果我将 requestfocus 与按钮 Action 监听器一起使用,它就会起作用。我想在表单加载时设
我的 Activity 中有一个编辑文本,想请求关注它。但是,它总是在启动 Activity 时崩溃。 Java代码: foodText = (EditText) findViewById(R.id.
我希望我的应用程序中的 EditText 在应用程序启动时默认具有光标。我尝试使用 还有 userIdInput = (EditText)findViewById(R.id.idInpu
在上面的标记中 不起作用。 Activity 启动时, TextView 未获得焦点。这是因为覆盖 TextView 的进度条吗?有什么解决办法吗
根据图库的位置,一个或另一个编辑文本将接收焦点。虽然我可以做到这一点,但行为的画廊崩溃了:当画廊运行一个位置并将焦点设置在编辑文本上时,画廊的速度崩溃。看来 Gallery 速度太慢,无法按时收到请求
调用 Component.requestFocus() 和手动聚焦某个组件(例如,使用键盘或鼠标聚焦)都会触发 FocusEvent.FOCUS_GAINED。 我正在监听 AWT 事件。 我的问题是
我正在尝试以编程方式指定当用户按下键盘上的下一个按钮时焦点所在的位置。我可以让它为某些人工作,但我有一个情况, View 被跳过,它下面的 View 获得焦点。 我进入了调试器,焦点确实经过了我的 V
全新方向 以下是我的问题的 SSCCE。我试图在输入输入时更新字段,在这种情况下,必须失去焦点才能进行更新。 package test; import java.awt.EventQueue; imp
当用户按键盘上的 Enter 键时,我将焦点从一个 AutoCompleteTextView 切换到另一个 AutoCompleteTextView。问题是当下一个 AutoCompleteTextV
接下来我有多个 Edittexts,我在 xml 中添加了 nextFocus 值。 但是根据未成年人复选框值的状态,一个编辑文本是可见的还是不可见的。所以我需要在 YYYY 编辑文本之后动态地关注它
我在控制对焦方面遇到了一些问题。我的接口(interface)定义如下: 来源( radio 组/可选)目的地(编辑文本)数量(编辑文本)转移(按钮) 我正在将“源代码”的可见性更改为我的代码。当我不
我遇到了一个恼人的屏幕问题。屏幕由一堆 Spinner 组成,一个在另一个下,然后在 Spinner 下方,一个 EditText。 问题是当屏幕启动时,EditText 有焦点,这意味着一些 Spi
我有一个 jDialog,其中包含一些需要聚焦的字段。 我看到一些奇怪的行为,有时聚焦会失败,如果您按下 Tab 键,您可以在下面的底层父窗口中看到焦点发生变化,很明显焦点没有转移。 我读了一篇关于聚
解决这个问题花了很多时间,看起来很容易,但我真的很累,找不到解决方案。我有一个 Activity , Activity 有 4 个 EditText 组件,其中 2 个有包含列表的弹出菜单(Alert
我在按下按钮时膨胀 View 。膨胀 View 就像一个对话框,但是当我尝试使用 requestFocus() 将焦点放在对话框上时,requestFocus() 返回 false 意味着我没有将焦点
下面是我为将焦点从一个编辑文本转移到另一个编辑文本而编写的一段代码,但是我在这个实现中遇到的问题是,焦点移动到特定的编辑文本,然后突然移动到下一个编辑文本。所以,我无法输入任何内容,因为焦点根本不在那
想知道 RequestFocus 和 ReqeustFocusFromTouch 之间的实际区别。何时应该使用每种方法,如何使用每种方法,以及每种方法在哪些情况下有用? 举一些例子并详细解释。 最佳答
我有 Action 线程,因为它是 Swing 软件,EDT。 我希望我的程序绘制对话框窗口,当它出现并且充满数据时,我希望将焦点放在选定的文本字段上。 代码流程:当我执行时,它将运行主线程,该线程在
我在 AnchorPane 中嵌入了一个 TextField 以及几个按钮。默认情况下,TextField 没有焦点,因为我希望它显示提示文本(请参阅 prompttext in textfield
我是一名优秀的程序员,十分优秀!