EditText上不能设置启用回真正的
问题描述:
我有一个EditText pageTitle
后进行编辑,并且它应该只可编辑,如果我的RelativeLayout addPhotoLayout
是不可见的。这是我的代码:EditText上不能设置启用回真正的
if(addPhotoLayout.getVisibility() == View.VISIBLE) {
pageTitle.setEnabled(false);
} else {
pageTitle.setEnabled(true);
}
的问题是,即使addPhotoLayout
消失或不再可见,pageTitle
不会恢复到可编辑状态。我曾尝试更改focusable
和focusableInTouchMode
的值,但同样的问题仍然存在。 The source code for the entire activity is here。
答
您需要在更新的addPhotoLayout
知名度,更新的pageTitle
状态。 在您的setMomentPicture
方法中,您将addPhotoLayout
的可见性设置为GONE
,但pageTitle
未收到通知。
您可以实现这样的方法:
private method setAddPhotoLayoutVisible(boolean setVisible) {
if(setVisible) {
addPhotoLayout.setVisibility(View.VISIBLE);
pageTitle.setEnabled(false);
} else {
addPhotoLayout.setVisibility(View.GONE);
pageTitle.setEnabled(true);
}
}
,并调用它,当你需要更新的addPhotoLayout
知名度。
尝试将setEditable设置为true,并将setFocusableInTouchMode设置为true,然后再试一次 –