ArrayList na List, poprawiono metode getItemViewType

This commit is contained in:
Naiki00 2021-02-15 23:50:32 +01:00
parent eb4997790f
commit 8d27949ed9
3 changed files with 7 additions and 67 deletions

View File

@ -1,4 +1,4 @@
package com.example.notatkon.note; package com.example.notatkon.adapter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -7,28 +7,23 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.Adapter;
import com.example.notatkon.R; import com.example.notatkon.R;
import com.example.notatkon.database.NoteEntity; import com.example.notatkon.entities.NoteEntity;
import org.w3c.dom.Text;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
//https://developer.android.com/guide/topics/ui/layout/recyclerview //https://developer.android.com/guide/topics/ui/layout/recyclerview
/* Aby klasa była adapterem musi dziedziczyć po RecyclerView.Adapter oraz wskazywać na ViewHolder */ /* Aby klasa była adapterem musi dziedziczyć po RecyclerView.Adapter oraz wskazywać na ViewHolder */
public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
private ArrayList<NoteEntity> arrNotes = new ArrayList<>(); private List<NoteEntity> listNotes;
//obiekt listy notatek
//private RecyclerView noteRecyclerView;
//konstruktor //konstruktor
public NoteAdapter(ArrayList<NoteEntity> arrNotes) { public NoteAdapter(ArrayList<NoteEntity> arrNotes) {
this.arrNotes = arrNotes; this.listNotes = arrNotes;
} }
//implementacja ViewHoldera //implementacja ViewHoldera
@ -70,12 +65,12 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
///// Replace the contents of a view (invoked by the layout manager) ///// Replace the contents of a view (invoked by the layout manager)
@Override @Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.setNote(arrNotes.get(position)); holder.setNote(listNotes.get(position));
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return arrNotes.size(); return listNotes.size();
} }
@Override @Override

View File

@ -1,28 +0,0 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstFragment">
<TextView
android:id="@+id/textview_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_first_fragment"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_first" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,27 +0,0 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondFragment">
<TextView
android:id="@+id/textview_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_second"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_second" />
</androidx.constraintlayout.widget.ConstraintLayout>