Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class ImageDisplayFragment : Fragment() {
// The recycler view is the root element of the Fragment's layout
// as such the view argument passed to onViewCreated() is the RecyclerView
with (view as RecyclerView) {
adapter = CustomRecyclerAdapter(images)
if(::images.isInitialized)
adapter = CustomRecyclerAdapter(images)
layoutManager = GridLayoutManager(requireContext(), 2)
}
}
Expand All @@ -53,4 +54,11 @@ class ImageDisplayFragment : Fragment() {
}
}
}

fun setimage(newimages: IntArray){
images = newimages
val adapter = CustomRecyclerAdapter(newimages)
view?.run {
(view as RecyclerView).adapter = adapter}
}
}
8 changes: 5 additions & 3 deletions app/src/main/java/edu/temple/inclassactivity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package edu.temple.inclassactivity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.fragment.app.Fragment

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -12,8 +14,8 @@ class MainActivity : AppCompatActivity() {
val typedArray = resources.obtainTypedArray(R.array.image_ids)
val imageArray = IntArray(typedArray.length()) {typedArray.getResourceId(it, 0)}
typedArray.recycle()

// Attach an instance of ImageDisplayFragment using factory method

findViewById<Button>(R.id.button).setOnClickListener{
(supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as ImageDisplayFragment).setimage(imageArray)
}
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,26 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="edu.temple.inclassactivity.ImageDisplayFragment"
android:layout_width="0dp"
android:layout_height="600dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fragmentContainerView" />
</androidx.constraintlayout.widget.ConstraintLayout>