how can i refresh the view of a fragment, when the back button is pressed?
I've tried this in the onResume method of the fragment but it doesn't work.
Ok, here is the code
the layout look like:
<RelativeLayout xmlns: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:orientation="horizontal"
android:background="@color/mainscreen_bg">
<fragment
android:id="@+id/topbar"
android:name="de.app.applib.TopbarFragment"
android:layout_width="match_parent"
android:layout_height="@dimen/topbar_height"
android:layout_alignParentTop="true"
tools:layout="@layout/fragment_topbar" />
<fragment
android:id="@+id/position_list"
android:name="de.app.applib.CriteriaListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@id/topbar"
android:tag="CriteriaList"
tools:layout="@layout/fragment_criterialist" />
The TopbarFragment has the following layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/topbar_bg" >
<ImageView android:id="@+id/topbar_home"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:src="@drawable/ic_ab_back_holo_light"
android:visibility="invisible"
android:padding="0dp"
android:contentDescription="@string/none"
android:layout_margin="0dp"/>
<ImageView android:id="@+id/topbar_logo"
android:src="@drawable/actionbar_logo"
android:layout_height="30dp"
android:layout_width="120dp"
android:layout_centerVertical="true"
android:padding="0dp"
android:layout_margin="0dp"
android:contentDescription="@string/none"
android:layout_toRightOf="@id/topbar_home"/>
<ToggleButton
android:id="@+id/topbar_btn_push_abo"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/topbar_btn_info"
android:layout_toLeftOf="@id/topbar_btn_info"
android:background="@drawable/topbar_btn_push_bg"
android:paddingTop="@dimen/padding_topbar_btn_push"
android:textOff=""
android:textOn=""
android:textSize="12sp" />
In the onCreateView() of the Fragment i set the textOn and textOff values of the toggleButton.
This Fragment is included in all activities.
Now, i want to update the text of the toggleButton when the user pressed the back button. I set the new text in the onResume() Method of the Fragment. This Method is called but the old text appears in the activity and not the new updated text.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG,"onCreateView called");
View v = inflater.inflate(ResourceUtils.getCustomizableLayoutID(getActivity(), "fragment_topbar"), container, false);
subscrButton = (ToggleButton) v.findViewById(R.id.topbar_btn_push_abo);
setCountOfNewAdds();
private void setCountOfNewAdds() {
int countOfNewAds = ((App)getActivity().getApplication()).getCountOfNewAds();
subscrButton.setTextOff(countOfNewAds>0?""+countOfNewAds:"");
subscrButton.setTextOn(countOfNewAds>0?""+countOfNewAds:"");
subscrButton.invalidate();
}
@Override
public void onResume() {
super.onResume();
setCountOfNewAdds();
}