Textview Settext And Setvisibility Not Working In Fragment
I have ControllerFragment which has 3 child fragments. Children fragments change are provided in the tabLayout via ViewPager. Unsend Apple and Banana badge count are computable var
Solution 1:
try to setVisibility android:visibility="visible"
or android:visibility="invisible"
delete gone
attribute it remove TextView.
<TextView
android:id="@+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="@drawable/tab_controller_badge"
android:gravity="center"
android:textColor="@color/white"
android:textSize="@dimen/miniTextSize"
android:visibility="visible" //change here
tools:text="11"
tools:visibility="visible" />
Solution 2:
Please use android:text
instead tools:text
- tools:text="text" is used only for Android Studio layout preview (wont be visible while running the app)
- android:text="text" is used to set text to a a layout element, which you can see when the app is run
Solution 3:
Try using the below xml,
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center"android:gravity="center"android:weightSum="2"android:orientation="horizontal"android:background="@color/Black"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:ellipsize="end"android:gravity="center"android:layout_gravity="center"android:maxLines="1"android:layout_weight="1.99"android:textColor="@color/white"android:textSize="@dimen/infoTitle"/><TextViewandroid:id="@+id/badgeView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="start|center"android:layout_marginEnd="1dp"android:layout_marginRight="1dp"android:layout_weight="0.01"android:background="@drawable/tab_controller_badge"android:gravity="center"android:textColor="@color/white"android:textSize="@dimen/miniTextSize"android:text="11"/></LinearLayout>
Hope it helps!
Solution 4:
I guess different thread problem. I have tried that eventBus for activity passing data to fragment and it solved.
ControllerFragment(){
@OverridepublicvoidonStart() {
super.onStart();
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().register(this);
}
@OverridepublicvoidonStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
publicvoidonEventMain(ControllerEvent event) {
if (event.getSelectedEventType() == ControllerEvent.tabControllerEventTypes.refreshCount.ordinal()) {
setUnSendAppleCount(event.getAppleCount());
}
}
}
Post a Comment for "Textview Settext And Setvisibility Not Working In Fragment"