简体   繁体   English

Android EditText字段可在模拟器上正常运行,但不能在设备上运行

[英]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.

相关问题 Android应用程序可以在模拟器中正常运行,但不能在真实设备中运行? - Android application works fine in emulator but not in real device? Android应用程序可以在模拟器上正常运行,但不能在真实设备上运行 - Android Application works fine on emulator but not on a real device Webview在模拟器上工作正常,但在设备上工作不正常 - Webview works fine on emulator but not on device Android应用程式可在模拟器上正常运作,但在真实装置中当机 - Android app works fine in emulator but crashes in real device Android系统。 模拟器突然出现问题,物理设备正常运行 - Android. Sudden problem with emulator, physical device works fine Android设备上的SQLite异常:没有这样的表,但是模拟器可以正常工作吗? - SQLite exception on Android Device : No such table, but emulator works fine? Android模拟器无法正确显示TextView(在设备上正常运行) - Android emulator not displaying a TextView properly (works fine on device) Mono Android-OverridePendingTransition在设备上不起作用,在模拟器中工作正常 - Mono Android - OverridePendingTransition not working on device, works fine in emulator 声音在Android设备上无效。 在模拟器上正常工作 - Sound won't work on android device. Works fine on emulator Flutter 电话身份验证在模拟器上工作正常,但在真实设备上不工作(Android) - Flutter Phone authentication works fine on emulator but not working on real device (Android)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM