- Forum-Beiträge: 14
14.01.2016, 18:03:23 via Website
14.01.2016 18:03:23 via Website
Hallo Leute,
als Neuling habe ich ein Problem mit der Umsetzung meines Projektes für Smartphones und Tablets.
Meine MainActivity mit NavigationDrawer ruft nach Klick auf einen Drawer-Eintrag ein ListFragment auf, das eine ListView anzeigt. Beim Klick auf einen Listeneintrag starte ich für Smartphones eine 2. Tab-Activity, die 3 Fragments in verschiedenen Pages über einen ViewPager verwaltet und in der ich die Details des geklickten Listenelements verwalte.
Jetzt möchte ich für Tablets diese Lösung anpassen, wobei ich mir vorstelle, das die Anzeige der 3 Fragments neben der ListView erfolgt.
Ich habe 2 Layouts für das Listfragment in layout und layout-sw600dp aufgebaut. Dabei enthält das Layout für Tablets einen Container, in dem ich die Anzeige realisieren möchte.
In der Methode onListItemClick des Listfragments unterscheide ich beide Varianten mit:
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
...
// Hat Layout Container? Nein: Tablet; Ja: SmartPhone
if (getView().findViewById(R.id.containerDetailsActivity) != null) {
// Tablet
// im Ordner für Tablets layout-sw600dp
// ???
} else {
// SmartPhones
// im Ordner für Tablets layout
// Start der Activity der Details
Intent intent = new Intent(getActivity(),MyDataDetailTabActivity.class);
// aktuelle Werte an activity und DetailsFragmente weitergeben
intent.putExtra(VALUE_ID, mId);
// intent.putExtra(VALUE_TITLE, mTitle);
// Aufruf Activity
getActivity().startActivity(intent);
}
}
Das Layout für das Tablet ist:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="...schemas.android.com/apk/res/android"
xmlns:app="...schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear_layout_data">
<!-- *** Tablet-Layout für DataFragment -->
<!-- Eingabebereich für neue Data + Liste -->
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/firstLinearLayout">
<!-- Eingabebereich für neue Data -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/inputLayout">
<!-- android:layout_marginRight="@dimen/marging_right" -->
<!-- +-Button für neue MyData -->
<ImageButton
android:layout_width="@dimen/icon_left_size"
android:layout_height="@dimen/icon_left_size"
android:src="@drawable/action_create_light"
android:id="@+id/buttonNewSlapData"
android:layout_margin="@dimen/margin_left_icon_all"
android:elevation="8dp"
android:background="@drawable/round_button_backround_small"
android:padding="@dimen/padding_icon_all"
android:cropToPadding="true" />
<!-- Eingabe Titel für neue MyData -->
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_top_row_text"
android:id="@+id/editTextNewSlapData"
android:textColor="@color/primary_text"
android:textSize="@dimen/abc_text_size_medium_material"
android:contentDescription="@string/description_editTextTitel"
android:hint="@string/hint_editTextTitel"
android:inputType="text"
android:imeOptions="actionDone"
android:layout_weight="1" />
<!-- android:textSize="@dimen/primary_text_size" -->
<!-- Zwischenspeicher für Antwort des Speichern-Dialogs -->
<TextView
android:id="@+id/ergebnis_vom_dialog"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- Liste MyData -->
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/list"
android:divider="@color/divider"
android:dividerHeight="@dimen/list_divider_height"
android:listSelector="@drawable/list_selector"
android:layout_weight="1"
android:layout_marginTop="@dimen/margin_list_view"
android:layout_marginBottom="@dimen/margin_list_view" />
</LinearLayout>
<!-- **** Container, in den die Activity mit den Details-Fragments kommen sollen-->
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@color/secondary_text"
android:id="@+id/containerDetailsActivity">
</FrameLayout>
Wie kann ich die geplante Details-Activity mit den 3 Fragments im Container laufen lassen? Muss ich gegebenenfalls ein anderes Steuerelement nutzen? Ich bin dankbar für Hinweise.
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.