fragment nicht aktualisieren, wenn die Zurücktaste gedrückt wird

wie kann ich die Ansicht aktualisieren, ein fragment, wenn Sie die zurück-Taste gedrückt wird?

Habe ich versucht, diese in der onResume-Methode der fragment-aber es funktioniert nicht.

Ok, hier ist der code

das layout Aussehen:

<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" />

Den TopbarFragment hat das folgende 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 der onCreateView() des Fragments ich die textOn und textOff Werte der toggleButton.

Diesem Fragment enthalten ist, in allen Aktivitäten.

Nun möchte ich den text aktualisieren der toggleButton, wenn der Benutzer betätigt die Schaltfläche "zurück".
Ich setze den neuen text in der onResume () - Methode des Fragments. Diese Methode wird aufgerufen, aber der alte text wird in der Aktivität und nicht die neuen, aktualisierten 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();
}
  • Es ist unklar, was Sie Fragen. Veröffentlichen Sie Ihren code und beschreiben Sie das problem klar
  • Ich habe einige code-Beispiele, um die Frage
InformationsquelleAutor Alex | 2013-11-18
Schreibe einen Kommentar