Skip to content

Commit 6e3afdd

Browse files
author
priyanka0906
committed
Implemented Recyclerview(clicklistener)
1 parent 131a65f commit 6e3afdd

File tree

7 files changed

+50
-13
lines changed

7 files changed

+50
-13
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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=".MainActivity2"></activity>
12+
<activity android:name=".CoilSample"></activity>
13+
<activity android:name=".ContourSample" />
1314
<activity android:name=".MainActivity">
1415
<intent-filter>
1516
<action android:name="android.intent.action.MAIN" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package playground.android
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
6+
class CoilSample : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_coil_sample)
10+
}
11+
}

android/src/main/java/playground/android/MainActivity2.kt renamed to android/src/main/java/playground/android/ContourSample.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package playground.android
33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55

6-
class MainActivity2 : AppCompatActivity() {
6+
class ContourSample : AppCompatActivity() {
77
override fun onCreate(savedInstanceState: Bundle?) {
88
super.onCreate(savedInstanceState)
9-
setContentView(R.layout.activity_main2)
9+
setContentView(MainView(this))
1010

1111
}
1212

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
66
import android.view.View
77
import android.view.ViewGroup
88
import android.widget.TextView
9+
import androidx.core.content.ContextCompat.startActivity
910
import androidx.recyclerview.widget.RecyclerView
1011

1112
class LibraryAdapter(private val context:Context, private val libraries:List<LibraryName>):RecyclerView.Adapter<LibraryAdapter.MyViewHolder>() {
@@ -26,6 +27,26 @@ class LibraryAdapter(private val context:Context, private val libraries:List<Lib
2627
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
2728
val library = libraries[position]
2829
holder.setData(library,position)
30+
holder.itemView.setOnClickListener { listener(library) }
31+
}
32+
33+
private fun listener(item: LibraryName) {
34+
35+
var intent = Intent()
36+
37+
when(item.name)
38+
{
39+
"Contour" -> {
40+
intent = Intent(context,ContourSample::class.java)
41+
}
42+
43+
"Coil" ->{
44+
intent = Intent(context,CoilSample::class.java)
45+
}
46+
}
47+
48+
context.startActivity(intent)
49+
2950
}
3051

3152
override fun getItemCount(): Int {
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+
<androidx.appcompat.widget.LinearLayoutCompat 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=".CoilSample">
8+
<TextView
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:text="Coil Sample"/>
12+
13+
</androidx.appcompat.widget.LinearLayoutCompat>

android/src/main/res/layout/activity_main2.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

android/src/main/res/layout/recyclerview_item.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:id="@+id/name_txt"
88
android:layout_width="match_parent"
99
android:layout_height="wrap_content"
10-
android:textSize="32sp"
10+
android:textSize="28sp"
1111
android:padding="5dp"
1212
android:layout_margin="10dp"
1313
/>

0 commit comments

Comments
 (0)