Entschuldigung, wenn das eine dumme Frage ist. Ich habe nach einer Antwort auf mein Problem gesucht und obwohl ich mehrere Erwähnungen dieses Problems gefunden habe, hat keine der vorgeschlagenen Lösungen mein Problem gelöst. In meiner App rufe ich eine Aktivität aus einem Fragment an und möchte dann durch einen Klick in der Aktivität zu diesem Fragment zurückkehren. 1 - In Fragment Discover_Fragment habe ich eine Listenansicht und wenn ein Element gedrückt wird, die Aktivität EditThoughts beginnt:Aufruf einer Aktivität aus Fragment
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent intent1 = new Intent(getActivity(), EditThought.class);
startActivity(intent1);
}
});
Aktivität EditThoughts startet ohne Probleme. 2 - Dann, als ich von Aktivität EditThought zum Fragmente (Discover_Fragment) zurückkehren möchte, verwende ich die folgenden:
FragmentManager fragmentManager = getSupportFragmentManager();
Discover_Fragment fragmentS1 = new Discover_Fragment();
fragmentManager.beginTransaction()
.replace(R.id.containerView, fragmentS1)
.commit();
Ich erhalte eine Fehlermeldung:
java.lang.IllegalArgumentException: No view found for id 0x7f0e006e (com.appleia.vocapp:id/containerView) for fragment Discover_Fragment{f1e7d01 #0 id=0x7f0e006e}
R.id.containerView ist die ID für die FrameLayout in activity_main:
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerView">
</FrameLayout>
das Layout für Discover_Fragment ist:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toplayout"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/topButtons"
android:gravity="center"
android:layout_weight="1">
<com.appleia.SegmentedButtons.SegmentedRadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:orientation="horizontal"
android:id="@+id/segment_text"
android:checkedButton="@+id/button_one"
android:gravity="center">
<RadioButton android:id="@id/button_one"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:minWidth="110dp"
android:minHeight="33dip"
android:text="@string/Articles"
android:textAppearance="?android:attr/textAppearanceLarge"
android:button="@null"
android:gravity="center"
android:textColor="@drawable/radio_colors" />
<RadioButton android:id="@+id/button_two"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:minWidth="0dp"
android:minHeight="33dip"
android:text="Two"
android:button="@null"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@drawable/radio_colors"
android:visibility="gone"/>
<RadioButton android:id="@+id/button_three"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:minWidth="110dp"
android:minHeight="33dip"
android:text="@string/Toughts"
android:button="@null"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@drawable/radio_colors" />
</com.appleia.SegmentedButtons.SegmentedRadioGroup>
</LinearLayout>
</LinearLayout>
<ListView
android:layout_below="@+id/toplayout"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
Was mache ich falsch? Vielen Dank im Voraus.
Alex, vielen Dank. Ich habe versucht, die startActivityFroResult, aber nicht wissen, wie onBackPressed implementieren. Welchen Code müsste ich dort hinzufügen? – user3079872
'onBackPressed' wird automatisch aufgerufen, wenn Sie die Zurück-Taste drücken. Wenn Sie das manuell machen möchten und die Zurück-Taste drücken, sollten Sie 'super.onBackPressed(); 'wann immer du willst. –
Schön zu hören, dass hilft. Happy coding;) –