重新加载可扩展列表时如何重新获得编辑文本的焦点...?
我有一个 ExpandableListView,其中我在组视图和子视图中加载自定义布局。
他们有一些编辑文本字段。
当我单击编辑文本时,会出现软键盘,此时会重新加载列表,但焦点不会位于编辑文本上。
因此,我正在键入的输入未输入到该编辑文本中。
如果我再次单击编辑文本,我可以输入值。
但即使在重新加载列表视图后我也想重新获得焦点。
我尝试在重新加载时存储最后单击的视图并将其存储在临时变量 requestFocus()
中,但它不起作用。
如何实现这个..?
这是一个屏幕截图。
如果有人有想法请帮助我..!
提前致谢。
I have a ExpandableListView in which i am loading custom layouts in both group and child views.
They are having some edit text fields.
When i click on the edit text, the soft keyboard appears, that time the list is reloaded, but focus will not be on the edit text.
As a result the input i am typing is not entered in that edit text.
If i clicked on the edit text again i can enter the values.
But I want to regain its focus even after reloading the list view.
I tried with storing the last clicked view and storing it in temporary variable, requestFocus()
on reloading, but its not working.
How to achieve this..?
here is a screen shot.
If anybody have an idea please help me..!
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
什么不起作用?您的活动是否正在重新创建,因此临时变量正在丢失?如果是这样,那么这个答案可能对您有帮助。
我以前没有使用过 ExpandableListView,但我必须在代码中解决类似的问题。当方向发生变化时,活动将被销毁,然后重新创建,因此我使用 onRetainNonConfigurationInstance() 来存储我想要保留的信息。
下面是一些示例代码:
然后,您只需在用户第一次触摸 EditText 时设置
mStoredState.mFieldToGiveFocusTo
即可。What isn't working? Is your activity being recreated so the temporary variable is being lost? If so, then this answer might help you.
I haven't used an ExpandableListView before, but I've had to solve a similar problem in my code. When an orientation change happens the activity is destroyed and then recreated, so I use
onRetainNonConfigurationInstance()
to store information that I want to preserve.Here's some sample code:
Then you just need to set
mStoredState.mFieldToGiveFocusTo
when the user first touches the EditText.我在
onCreate()
或onResume()
内调用requestFocus()
时遇到了类似的问题。我通过稍微延迟设置焦点来解决这个问题。像这样的东西可能对你有用:我认为问题的根源可能是 AndroidFramework 在处理 onResume() 后设置焦点。这就是为什么延迟可能会有所帮助。
I had similar problems with calling
requestFocus()
insideonCreate()
oronResume()
. I was able to solve this by setting the focus with a slight delay. Something like this might work for you:I think the root of the problem might be that the AndroidFramework sets the Focus after onResume() is processed. So that's why a delay might help.
管理您的活动的 SoftInput 键盘。
看看 android:windowSoftInputMode
Manage the SoftInput Keyboard for your activity.
Take a look at android:windowSoftInputMode
我想你会在这里找到答案:
ExpandableListView 子项在触摸时不会获得焦点
这个人有一个听起来与您的问题相同的问题。
I think you will find the answer here:
ExpandableListView child items don't get focus when touched
This guy has an issue that sounds the same as yours.
展开 listView 后,您可以通过添加此行
editText.requestFocus();来强制获得对 editText 的焦点。
After the listView is expanded, you gain force gain focus on the editText by adding this line,
editText.requestFocus();