Java setEnabled无法在Android中的某些设备上工作
我的屏幕上有一个按钮,当用户执行一些操作时,它会动态启用或禁用。以下是更改按钮状态的代码:Java setEnabled无法在Android中的某些设备上工作,java,android,button,Java,Android,Button,我的屏幕上有一个按钮,当用户执行一些操作时,它会动态启用或禁用。以下是更改按钮状态的代码: private void setContinueButtonStatus() { boolean status = false; // Every time user selects a ticket this is increased for (TicketSpecification specification : ticketSpecifica
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"/>
我的问题是,这段代码在MotoG5S中运行良好,在用户交互后使按钮启用或不启用
但在GalaxyS9和Android Emulator(我使用的是Pixel XL)上,即使在用户点击后,按钮仍保持禁用状态。但是,如果我点击按钮,它将被启用并正常执行点击
有人知道这是安卓上的一个bug,还是我做错了什么?我在这里发现了这个bug 我使用一个外部库来管理我的应用程序上的一些东西,这个库返回了更新非主线程上的按钮所需的信息
我通过将代码重定向到主线程解决了这个问题。我在这里发现了错误 我使用一个外部库来管理我的应用程序上的一些东西,这个库返回了更新非主线程上的按钮所需的信息
我通过将代码重定向到主线程解决了这个问题。您是否尝试了按钮xml中的
focusable=“false”
属性?是的,我尝试过。您尝试了按钮xml中的focusable=“false”
属性吗?是的,我尝试过。