Browse Source

CustomAdapter isn't detected, but anything else from RecycleView/ is working

Simon Hammer 4 years ago
parent
commit
c579d9abaa

+ 72 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/home/CustomAdapter.java

@@ -0,0 +1,72 @@
+package com.noahvogt.miniprojekt.ui.home;
+
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.noahvogt.miniprojekt.R;
+
+public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
+
+    private String[] localDataSet;
+
+    /**
+     * Provide a reference to the type of views that you are using
+     * (custom ViewHolder).
+     */
+    public static class ViewHolder extends RecyclerView.ViewHolder {
+        private final TextView textView;
+
+        public ViewHolder(View view) {
+            super(view);
+            // Define click listener for the ViewHolder's View
+
+            textView = (TextView) view.findViewById(R.id.textView);
+        }
+
+        public TextView getTextView() {
+            return textView;
+        }
+    }
+
+    /**
+     * Initialize the dataset of the Adapter.
+     *
+     * @param dataSet String[] containing the data to populate views to be used
+     * by RecyclerView.
+     */
+    public CustomAdapter(String[] dataSet) {
+        localDataSet = dataSet;
+    }
+
+    // Create new views (invoked by the layout manager)
+    @Override
+    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
+        // Create a new view, which defines the UI of the list item
+        View view = LayoutInflater.from(viewGroup.getContext())
+                .inflate(R.layout.activity_main, viewGroup, false);
+
+        return new ViewHolder(view);
+    }
+
+    // Replace the contents of a view (invoked by the layout manager)
+    @Override
+    public void onBindViewHolder(ViewHolder viewHolder, final int position) {
+
+        // Get element from your dataset at this position and replace the
+        // contents of the view with that element
+        viewHolder.getTextView().setText(localDataSet[position]);
+    }
+
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return localDataSet.length;
+    }
+}
+

+ 1 - 1
app/src/main/java/com/noahvogt/miniprojekt/ui/home/HomeFragment.java

@@ -23,7 +23,7 @@ public class HomeFragment extends Fragment {
         homeViewModel =
         homeViewModel =
                 new ViewModelProvider(this).get(HomeViewModel.class);
                 new ViewModelProvider(this).get(HomeViewModel.class);
         View root = inflater.inflate(R.layout.fragment_home, container, false);
         View root = inflater.inflate(R.layout.fragment_home, container, false);
-        final TextView textView = root.findViewById(R.id.text_home);
+        final TextView textView = root.findViewById(R.id.flower_text);
         homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
         homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
             @Override
             @Override
             public void onChanged(@Nullable String s) {
             public void onChanged(@Nullable String s) {

+ 17 - 0
app/src/main/res/layout/activity_main.xml

@@ -35,4 +35,21 @@
             android:layout_marginBottom="20dp"
             android:layout_marginBottom="20dp"
             android:text="Add Email" />
             android:text="Add Email" />
     </com.google.android.material.navigation.NavigationView>
     </com.google.android.material.navigation.NavigationView>
+
+    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+        <!--android:layout_marginLeft="@dimen/margin_medium"
+        android:layout_marginRight="@dimen/margin_medium"
+        android:gravity="center_vertical"-->
+
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/recycler_view"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"/>
+        <!--android:text="@string/element_text"-->
+    </FrameLayout>
+
 </androidx.drawerlayout.widget.DrawerLayout>
 </androidx.drawerlayout.widget.DrawerLayout>

+ 1 - 1
app/src/main/res/layout/app_bar_main.xml

@@ -27,7 +27,7 @@
         android:id="@+id/toolbar"
         android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="?attr/actionBarSize"
         android:layout_height="?attr/actionBarSize"
-        android:layout_gravity="bottom"
+        android:layout_gravity="top"
         android:background="?attr/colorPrimary"
         android:background="?attr/colorPrimary"
         app:popupTheme="@style/Theme.MiniProjekt.PopupOverlay" />
         app:popupTheme="@style/Theme.MiniProjekt.PopupOverlay" />
 
 

+ 43 - 17
app/src/main/res/layout/fragment_home.xml

@@ -1,23 +1,49 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
+<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context=".ui.home.HomeFragment">
+    android:layout_height="wrap_content"
+    android:paddingLeft="16dp"
+    android:paddingTop="16dp"
+    android:paddingRight="16dp"
+    android:layout_gravity="top">
 
 
+    <!-- Add in TextView to display flower name   -->
     <TextView
     <TextView
-        android:id="@+id/text_home"
-        android:layout_width="match_parent"
+        android:id="@+id/flower_text"
+        android:layout_column="0"
+        android:layout_row="0"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:layout_gravity="center_horizontal"
-        android:textAlignment="center"
+        android:layout_width="wrap_content"
+        android:textSize="25dp"
+        android:text="@string/Sender"/>
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_row="1"
+        android:layout_column="0"
+        android:text="@string/Betreff"
         android:textSize="20sp"
         android:textSize="20sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-</androidx.constraintlayout.widget.ConstraintLayout>
+        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
+        android:textColor="@color/colorBetreff" />
+
+    <TextView
+        android:text="@string/Beginn"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_row="2"
+        android:layout_column="0"
+        android:gravity="left"
+        android:textSize="20sp" />
+
+    <TextView
+        android:text="@string/date"
+        android:textSize="20dp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_row="0"
+        android:layout_column="3"
+        android:gravity="left" />
+
+
+</GridLayout>

+ 5 - 0
app/src/main/res/values/colors.xml

@@ -7,4 +7,9 @@
     <color name="teal_700">#FF018786</color>
     <color name="teal_700">#FF018786</color>
     <color name="black">#FF000000</color>
     <color name="black">#FF000000</color>
     <color name="white">#FFFFFFFF</color>
     <color name="white">#FFFFFFFF</color>
+
+    <color name="colorPrimary">#6200EE</color>
+    <color name="colorPrimaryDark">#3700B3</color>
+    <color name="colorAccent">#03DAC5</color>
+    <color name="colorBetreff">#3EC143</color>
 </resources>
 </resources>

+ 22 - 0
app/src/main/res/values/strings.xml

@@ -11,4 +11,26 @@
     <string name="drawer_sent">Sent</string>
     <string name="drawer_sent">Sent</string>
     <string name="drawer_drafts">Drafts</string>
     <string name="drawer_drafts">Drafts</string>
 
 
+    <string name="Sender">Absender</string>
+    <string name="Betreff">Betreff</string>
+    <string name="Beginn">E-mail Beginn</string>
+    <string name="date">22. Apr.</string>
+
+    <!-- Add in flower names  -->
+    <string-array name="flower_array">
+        <item>Lily</item>
+        <item>Poppy</item>
+        <item>Sunflower</item>
+        <item>Freesia</item>
+        <item>Daisy</item>
+        <item>Rose</item>
+        <item>Daffodil</item>
+        <item>Lavender</item>
+        <item>Peony</item>
+        <item>Lilac</item>
+        <item>Dahlia</item>
+        <item>Tulip</item>
+        <item>Dandelion</item>
+    </string-array>
+
 </resources>
 </resources>