diff options
author | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-02-16 11:37:58 +0100 |
---|---|---|
committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-02-16 11:37:58 +0100 |
commit | 7288d5ae154f895d71727acc92828aa555e8108b (patch) | |
tree | 367d04058f951c24a1bc4778b85873df89bf67f8 /app/src/main/java/xyz/adjutor | |
parent | 97ff499413e5dae958ac3741616e2ee84a188871 (diff) |
Starting to work on recycler view feature
Diffstat (limited to 'app/src/main/java/xyz/adjutor')
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt | 45 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/MainActivity.kt | 1 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt | 1 |
3 files changed, 47 insertions, 0 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt new file mode 100644 index 0000000..74ba9c4 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt @@ -0,0 +1,45 @@ +package xyz.adjutor.aniki + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView + +class ListAdapter(private val dataSet: Array<String>) : + RecyclerView.Adapter<ListAdapter.ViewHolder>() { + + /** + * Provide a reference to the type of views that you are using + * (custom ViewHolder). + */ + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + // Define click listener for the ViewHolder's View. + val firstLine: TextView = view.findViewById(R.id.firstLine) + val secondLine: TextView = view.findViewById(R.id.secondLine) + + } + + // Create new views (invoked by the layout manager) + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder { + // Create a new view, which defines the UI of the list item + val view = LayoutInflater.from(viewGroup.context) + .inflate(R.layout.row_layout, viewGroup, false) + + return ViewHolder(view) + } + + // Replace the contents of a view (invoked by the layout manager) + override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { + + // Get element from your dataset at this position and replace the + // contents of the view with that element + viewHolder.firstLine.text = dataSet[position] + viewHolder.secondLine.text = dataSet[position] + } + + // Return the size of your dataset (invoked by the layout manager) + override fun getItemCount() = dataSet.size + +} + diff --git a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt index 4ccae64..3ae1bf2 100644 --- a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt @@ -6,6 +6,7 @@ import com.google.android.material.snackbar.Snackbar import androidx.appcompat.app.AppCompatActivity import android.view.Menu import android.view.MenuItem +import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() { diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt index c64b9fe..a59e038 100644 --- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt @@ -27,5 +27,6 @@ class TopMangaPage : Fragment() { view.findViewById<Button>(R.id.home).setOnClickListener { findNavController().navigate(R.id.action_TopMangaPage_to_HomePage) } + } }
\ No newline at end of file |