[英]Android setVisibility(View.VISIBLE) not working at all after screen rotation in KITKAT
Please note that same code is working perfectly fine on Android Versions > KitKat
请注意,相同的代码在Android版本> KitKat上运行得非常好
I have a dynamic view of questionnaire. 我对调查问卷有一个动态的看法。 All views are being added according to question coming up from the api I am using.
所有观点都是根据我正在使用的api提出的问题添加的。 What I am trying to do is, If question was required but user didn't filled it and trying to submit it, I am trying to setVisibility as 'VISIBLE' to my TextView having text "Required"
我想要做的是,如果问题是必需的,但用户没有填写它并尝试提交它,我试图将“可见性”设置为“VISIBLE”到我的TextView,文本“必需”
It works perfectly fine when I am either in Landscape or in Portrait mode, but right after changing the orientation, it stops working. 当我处于横向或纵向模式时,它完全正常,但在更改方向后,它会停止工作。
I have debugged the code and checked, status of visibility is being changed but UI is not being updated. 我已经调试了代码并进行了检查,可见性状态正在改变,但UI没有更新。
It is working fine other than KITKAT
除了KITKAT之外它工作得很好
I have tried view.invalidate(); 我试过view.invalidate(); as well.
同样。
TextView layout to be set as VISIBLE TextView布局设置为VISIBLE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/required_prompt_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.goodsnitch.lib.ui.LatoRegularTextView
android:id="@+id/required_prompt_dynamic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/field_required_prompt"
android:textColor="@android:color/holo_red_light"
android:textSize="11dp"
android:textStyle="italic"
android:visibility="gone" />
</LinearLayout>
Java Code to make it visible Java代码使其可见
private void showRequiredPrompt(final View view) {
final TextView requiredLabel = (TextView) ((LinearLayout) view.getParent()).findViewById(R.id.required_prompt_dynamic);
if (requiredLabel != null) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
view.clearAnimation();
requiredLabel.clearAnimation();
requiredLabel.setVisibility(View.VISIBLE);
view.invalidate();
requiredLabel.invalidate();
}
}, 200);
}
}
I will appreciate your help :) 我将非常感谢你的帮助:)
Editing question to explain further 编辑问题进一步解释
This is code to show the label ON CLICK EVENT This is the toast showing visibility state of the label 这是显示标签ON CLICK EVENT的代码这是显示标签 可见性状态的toast
Required label should appear just above first checkbox in RED color 所需标签应出现在RED颜色的第一个复选框上方
当你使用屏幕旋转时,使用onSaveInstanceState()和onRestoreInstanceState()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.