dsNDesign
Erfahrenes Mitglied
Hei,
ich habe ein ListFragment, in welchem ich bei der onListItemClick-Funktion eine neue Activity starten möchte.
Das sieht wie folgt aus:
Und hier die Activity:
Diese soll ein neues Fragment anzeigen:
Mein ListFragment wird auch richtig angezeigt. Sobald ich jedoch ein Item auswähle stürzt meine App ab. Jemand eine Idee, woran das liegen könnte?
Gruß
PS: Hier noch die XMLs
Edit:
Problem gelöst.
Hatte vergessen, die neue Activity in die Manifest Datei einzufügen.
ich habe ein ListFragment, in welchem ich bei der onListItemClick-Funktion eine neue Activity starten möchte.
Das sieht wie folgt aus:
Java:
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
Intent detailIntent = new Intent(getActivity().getApplicationContext(), ItemDetailActivity.class);
startActivity(detailIntent);
}
Und hier die Activity:
Java:
public class ItemDetailActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_detail);
getActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.item_detail_container, new ItemDetailFragment())
.commit();
}
}
}
Diese soll ein neues Fragment anzeigen:
Java:
public class ItemDetailFragment extends Fragment {
public ItemDetailFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.textView);
textView.setText("Test");
return rootView;
}
}
Mein ListFragment wird auch richtig angezeigt. Sobald ich jedoch ein Item auswähle stürzt meine App ab. Jemand eine Idee, woran das liegen könnte?
Gruß
PS: Hier noch die XMLs
XML:
// activity_item_detail
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_detail_container">
</FrameLayout>
XML:
// fragment_item_detail
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Edit:
Problem gelöst.
Hatte vergessen, die neue Activity in die Manifest Datei einzufügen.
Zuletzt bearbeitet von einem Moderator: