Skip to content

Commit 131a65f

Browse files
author
priyanka0906
committed
Implemented Recyclerview.
1 parent 61d3ef2 commit 131a65f

File tree

8 files changed

+108
-3
lines changed

8 files changed

+108
-3
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="playground.android">
3+
package="playground.android">
44

55
<application
66
android:allowBackup="true"
@@ -9,7 +9,8 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/Theme.AppCompat.NoActionBar">
12-
<activity android:name="playground.android.MainActivity">
12+
<activity android:name=".MainActivity2"></activity>
13+
<activity android:name=".MainActivity">
1314
<intent-filter>
1415
<action android:name="android.intent.action.MAIN" />
1516

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package playground.android
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.view.LayoutInflater
6+
import android.view.View
7+
import android.view.ViewGroup
8+
import android.widget.TextView
9+
import androidx.recyclerview.widget.RecyclerView
10+
11+
class LibraryAdapter(private val context:Context, private val libraries:List<LibraryName>):RecyclerView.Adapter<LibraryAdapter.MyViewHolder>() {
12+
inner class MyViewHolder(itemView: View):RecyclerView.ViewHolder(itemView) {
13+
val name:TextView = itemView.findViewById(R.id.name_txt)
14+
15+
fun setData(library: LibraryName, position: Int) {
16+
name.text = library.name
17+
18+
}
19+
}
20+
21+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
22+
val view = LayoutInflater.from(context).inflate(R.layout.recyclerview_item,parent,false)
23+
return MyViewHolder(view)
24+
}
25+
26+
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
27+
val library = libraries[position]
28+
holder.setData(library,position)
29+
}
30+
31+
override fun getItemCount(): Int {
32+
return libraries.size
33+
}
34+
}

android/src/main/java/playground/android/MainActivity.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ package playground.android
22

33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
5+
import androidx.recyclerview.widget.RecyclerView
6+
7+
58

69

710
class MainActivity : AppCompatActivity() {
811
override fun onCreate(savedInstanceState: Bundle?) {
912
super.onCreate(savedInstanceState)
10-
setContentView(MainView(this))
13+
setContentView(R.layout.activity_main)
14+
val recyclerView : RecyclerView = findViewById(R.id.recyclerView)
15+
val adapter = LibraryAdapter(this,Suppliers.libraries)
16+
recyclerView.adapter = adapter
17+
18+
19+
1120

1221
}
1322
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package playground.android
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
6+
class MainActivity2 : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_main2)
10+
11+
}
12+
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package playground.android
2+
3+
data class LibraryName(var name:String)
4+
5+
6+
object Suppliers{
7+
val libraries = listOf(LibraryName("Contour"),
8+
LibraryName("Coil"),
9+
10+
11+
)
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
xmlns:app="http://schemas.android.com/apk/res-auto">
6+
7+
<androidx.recyclerview.widget.RecyclerView
8+
android:id="@+id/recyclerView"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"
11+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
12+
android:orientation="vertical"/>
13+
</LinearLayout>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity2">
8+
9+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content">
5+
6+
<TextView
7+
android:id="@+id/name_txt"
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:textSize="32sp"
11+
android:padding="5dp"
12+
android:layout_margin="10dp"
13+
/>
14+
</androidx.cardview.widget.CardView>

0 commit comments

Comments
 (0)