Add articles list
This commit is contained in:
parent
5457565244
commit
f29e6dcdbb
5 changed files with 73 additions and 1 deletions
app
|
@ -38,6 +38,7 @@ dependencies {
|
|||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.causa_arcana
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class ArticlesListRecyclerViewAdapter:
|
||||
RecyclerView.Adapter<ArticlesListRecyclerViewAdapter.ViewHolder>()
|
||||
{
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.rvitem_article_card, parent, false),
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.titleTextView?.text = when (position) {
|
||||
0 -> "Foo"
|
||||
1 -> "Bar"
|
||||
2 -> "Car"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return 3
|
||||
}
|
||||
|
||||
class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
var titleTextView: TextView? = null
|
||||
|
||||
init {
|
||||
titleTextView = itemView.findViewById(R.id.rvitem_article_card__title_text_view)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,10 +2,17 @@ package com.causa_arcana
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
val articlesListRecyclerView: RecyclerView =
|
||||
findViewById(R.id.activity_main__articles_list_rv)
|
||||
articlesListRecyclerView.layoutManager = LinearLayoutManager(this)
|
||||
articlesListRecyclerView.adapter = ArticlesListRecyclerViewAdapter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,15 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/activity_main__articles_list_rv"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:listitem="@layout/rvitem_article_card"/>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
14
app/src/main/res/layout/rvitem_article_card.xml
Normal file
14
app/src/main/res/layout/rvitem_article_card.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rvitem_article_card__title_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Hello, World!"/>
|
||||
|
||||
</LinearLayout>
|
Reference in a new issue