[英]Android EditText field works fine on emulator, but not device
I'm having a strange problem. 我有一个奇怪的问题。 What I did was to make a custom ListView adapter with TextViews and EditText fields. 我所做的是制作一个带有TextViews和EditText字段的自定义ListView适配器。 When I press a button, the app takes the EditText field values and saves them to the device's SD card. 当我按下按钮时,应用程序将使用EditText字段值并将其保存到设备的SD卡中。
My app works perfectly fine on the emulator, but the problem is that the EditText fields keep deselecting themselves when I test it on my device. 我的应用程序在模拟器上可以正常运行,但是问题是当我在设备上对其进行测试时,EditText字段会自行取消选择。 In other words, I would click the EditText field, the keyboard and cursor would pop up, but the cursor would them immediately dissappear afterwards, making it impossible to input any text. 换句话说,我将单击EditText字段,键盘和光标将弹出,但随后光标将立即消失,从而使得无法输入任何文本。
My custom adapter code: 我的自定义适配器代码:
@Override
public View getView(int i, View view, ViewGroup viewGroup)
{
if (view == null)
{
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
view = inflater.inflate(R.layout.list_item_task_detail, viewGroup, false);
}
final TaskDetailModel taskDetailModel = listArray.get(i);
TextView textView = (TextView)view.findViewById(R.id.list_item_task_detail_text_view);
textView.setText(taskDetailModel.getTaskName());
EditText editText = (EditText)view.findViewById(R.id.list_item_task_detail_edit_text);
return view;
}
The EditText layout entry: EditText布局条目:
<EditText
android:id="@+id/list_item_task_detail_edit_text"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
Is there some kind of editable = true I need to add to the EditText field? 我需要添加某种Editable = true吗? I feel that I'm making a mistake somewhere that I can't seem to find. 我觉得我在某个似乎找不到的地方犯了一个错误。 I also just don't understand why the app works on the emulator and not on my real phone. 我也只是不明白为什么该应用程序可以在模拟器上运行,而不能在我的真实手机上运行。
BTW the emulator and my phone use the same SDK version, API level 19 (4.4.x) BTW模拟器和我的手机使用相同的SDK版本,API级别19(4.4.x)
I think I managed to fix my own problem... 我想我设法解决了自己的问题...
All I needed to do was to add the line 我要做的就是添加行
editText.requestFocus()
to my adapter. 到我的适配器。
I'm guessing that the button's click listener overrides the EditText field's focus request if requestFocus() is not set for some strange reason. 我猜测如果由于某些奇怪的原因未设置requestFocus(),则按钮的单击侦听器将覆盖EditText字段的焦点请求。 Still don't know why this wasn't a problem on the emulator though 仍然不知道为什么这不是模拟器上的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.