[英]setEnabled not working on some devices in Android
我的屏幕上有一个按钮,当用户执行一些操作时,该按钮会动态启用或禁用。 这是更改按钮状态的代码:
private void setContinueButtonStatus() {
boolean status = false;
// Every time user selects a ticket this is increased
for (TicketSpecification specification : ticketSpecificationList.specifications) {
if (specification.getMyCount() > 0) {
status = true;
break;
}
}
findViewById(R.id.btnContinue).setEnabled(status);
}
我的按钮 xml 是:
<Button
android:id="@+id/btnContinue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/continue_button"
android:layout_alignParentBottom="true"/>
我的问题是此代码在 Moto G5S 中运行良好,在用户交互后启用或不启用按钮。
但是在 Galaxy S9 和 Android Emulator(我使用的是 Pixel XL)上,即使在用户点击之后,按钮仍然处于禁用状态。 但是,如果我点击按钮,它会被启用并正常执行点击。
任何人都知道这是Android上的错误,还是我做错了什么?
我在这里找到了错误。
我正在使用外部库来管理我的应用程序上的一些东西,并且这个库返回更新不是主线程的线程上的按钮所需的信息。
我已经通过将我的代码重定向到主线程来解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.