Skip to content

Commit dcd6ae0

Browse files
committed
feat #9: add Recyclerview to the main activity
1 parent c4d2492 commit dcd6ae0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Affirmations/.idea/workspace.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Affirmations/app/src/main/java/com/example/affirmations/MainActivity.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@ package com.example.affirmations
33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55
import android.widget.TextView
6+
import androidx.recyclerview.widget.RecyclerView
7+
import com.example.affirmations.adapter.ItemAdapter
68
import com.example.affirmations.data.Datasource
79

810
class MainActivity : AppCompatActivity() {
911
override fun onCreate(savedInstanceState: Bundle?) {
1012
super.onCreate(savedInstanceState)
1113
setContentView(R.layout.activity_main)
1214

15+
// initialize data
16+
val myDataset = Datasource().loadAffirmations()
17+
18+
// find the reference to the Recycler view within the layout
19+
val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
20+
21+
// assign the ItemAdapter object to the adapter property of the recyclerview
22+
recyclerView.adapter = ItemAdapter(this, myDataset)
23+
24+
// content do not change the layout size of the Recyclerview
25+
recyclerView.setHasFixedSize(true)
26+
1327

1428
}
1529
}

0 commit comments

Comments
 (0)